goep_server.c (2a4ebdf641323ac894b53065579d4f4556bff551) goep_server.c (c8e39cad4d468e8f30f3c3da4792ac3effa0aa86)
1/*
2 * Copyright (C) 2019 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 37 unchanged lines hidden (view full) ---

46#include "btstack_debug.h"
47#include "btstack_defines.h"
48#include "hci.h"
49#include "btstack_memory.h"
50#include "hci_dump.h"
51#include "btstack_event.h"
52
53#include "classic/goep_server.h"
1/*
2 * Copyright (C) 2019 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 37 unchanged lines hidden (view full) ---

46#include "btstack_debug.h"
47#include "btstack_defines.h"
48#include "hci.h"
49#include "btstack_memory.h"
50#include "hci_dump.h"
51#include "btstack_event.h"
52
53#include "classic/goep_server.h"
54#include "classic/obex.h"
54#include "classic/obex_message_builder.h"
55
56#ifdef ENABLE_GOEP_L2CAP
57#include "l2cap.h"
58
59static l2cap_ertm_config_t ertm_config = {
60 1, // ertm mandatory
61 2, // max transmit, some tests require > 1

--- 523 unchanged lines hidden (view full) ---

585 // workaround: limit OBEX packet len to L2CAP/RFCOMM MTU
586 maximum_obex_packet_length = btstack_min(maximum_obex_packet_length, connection->bearer_mtu);
587
588 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
589 uint16_t buffer_len = goep_server_get_outgoing_buffer_len(connection);
590 return obex_message_builder_response_create_connect(buffer, buffer_len, obex_version_number, flags, maximum_obex_packet_length, (uint32_t) goep_cid);
591}
592
55#include "classic/obex_message_builder.h"
56
57#ifdef ENABLE_GOEP_L2CAP
58#include "l2cap.h"
59
60static l2cap_ertm_config_t ertm_config = {
61 1, // ertm mandatory
62 2, // max transmit, some tests require > 1

--- 523 unchanged lines hidden (view full) ---

586 // workaround: limit OBEX packet len to L2CAP/RFCOMM MTU
587 maximum_obex_packet_length = btstack_min(maximum_obex_packet_length, connection->bearer_mtu);
588
589 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
590 uint16_t buffer_len = goep_server_get_outgoing_buffer_len(connection);
591 return obex_message_builder_response_create_connect(buffer, buffer_len, obex_version_number, flags, maximum_obex_packet_length, (uint32_t) goep_cid);
592}
593
593uint8_t goep_server_response_create_general(uint16_t goep_cid, uint8_t opcode){
594uint8_t goep_server_response_create_general(uint16_t goep_cid){
594 goep_server_connection_t * connection = goep_server_get_connection_for_goep_cid(goep_cid);
595 if (connection == NULL) {
596 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
597 }
598 goep_server_packet_init(connection);
599 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
600 uint16_t buffer_len = goep_server_get_outgoing_buffer_len(connection);
595 goep_server_connection_t * connection = goep_server_get_connection_for_goep_cid(goep_cid);
596 if (connection == NULL) {
597 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
598 }
599 goep_server_packet_init(connection);
600 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
601 uint16_t buffer_len = goep_server_get_outgoing_buffer_len(connection);
601 return obex_message_builder_response_create_general(buffer, buffer_len, opcode);
602 return obex_message_builder_response_create_general(buffer, buffer_len, OBEX_RESP_SUCCESS);
602}
603
604uint16_t goep_server_response_get_max_body_size(uint16_t goep_cid){
605 goep_server_connection_t * connection = goep_server_get_connection_for_goep_cid(goep_cid);
606 if (connection == NULL) {
607 return 0;
608 }
609 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);

--- 41 unchanged lines hidden (view full) ---

651 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
652 }
653
654 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
655 uint16_t buffer_len = goep_server_get_outgoing_buffer_len(connection);
656 return obex_message_builder_header_add_application_parameters(buffer, buffer_len, data, length);
657}
658
603}
604
605uint16_t goep_server_response_get_max_body_size(uint16_t goep_cid){
606 goep_server_connection_t * connection = goep_server_get_connection_for_goep_cid(goep_cid);
607 if (connection == NULL) {
608 return 0;
609 }
610 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);

--- 41 unchanged lines hidden (view full) ---

652 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
653 }
654
655 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
656 uint16_t buffer_len = goep_server_get_outgoing_buffer_len(connection);
657 return obex_message_builder_header_add_application_parameters(buffer, buffer_len, data, length);
658}
659
659uint8_t goep_server_execute(uint16_t goep_cid){
660uint8_t goep_server_execute(uint16_t goep_cid, uint8_t response_code){
660 goep_server_connection_t * connection = goep_server_get_connection_for_goep_cid(goep_cid);
661 if (connection == NULL) {
662 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
663 }
664
665 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
661 goep_server_connection_t * connection = goep_server_get_connection_for_goep_cid(goep_cid);
662 if (connection == NULL) {
663 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
664 }
665
666 uint8_t * buffer = goep_server_get_outgoing_buffer(connection);
667 // set reponse code
668 buffer[0] = response_code;
666 uint16_t pos = big_endian_read_16(buffer, 1);
667 switch (connection->type) {
668#ifdef ENABLE_GOEP_L2CAP
669 case GOEP_CONNECTION_L2CAP:
670 return l2cap_send(connection->bearer_cid, buffer, pos);
671 break;
672#endif
673 case GOEP_CONNECTION_RFCOMM:

--- 12 unchanged lines hidden ---
669 uint16_t pos = big_endian_read_16(buffer, 1);
670 switch (connection->type) {
671#ifdef ENABLE_GOEP_L2CAP
672 case GOEP_CONNECTION_L2CAP:
673 return l2cap_send(connection->bearer_cid, buffer, pos);
674 break;
675#endif
676 case GOEP_CONNECTION_RFCOMM:

--- 12 unchanged lines hidden ---