1 /* 2 * Copyright (C) 2014 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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #define BTSTACK_FILE__ "goep_client.c" 39 40 #include "btstack_config.h" 41 42 #include <stdint.h> 43 #include <stdio.h> 44 #include <stdlib.h> 45 #include <string.h> 46 47 #include "btstack_debug.h" 48 #include "hci_dump.h" 49 #include "bluetooth_sdp.h" 50 #include "btstack_event.h" 51 #include "classic/goep_client.h" 52 #include "classic/obex_message_builder.h" 53 #include "classic/obex.h" 54 #include "classic/obex_iterator.h" 55 #include "classic/rfcomm.h" 56 #include "classic/sdp_client.h" 57 #include "classic/sdp_util.h" 58 #include "l2cap.h" 59 60 //------------------------------------------------------------------------------------------------------------ 61 // goep_client.c 62 // 63 64 // #define ENABLE_GOEP_L2CAP 65 66 #ifdef ENABLE_GOEP_L2CAP 67 #ifndef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE 68 #error "ENABLE_GOEP_L2CAP requires ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE. Please enable ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE or disable ENABLE_GOEP_L2CAP" 69 #endif 70 #endif 71 72 typedef enum { 73 GOEP_INIT, 74 GOEP_W4_SDP, 75 GOEP_W4_CONNECTION, 76 GOEP_CONNECTED, 77 } goep_state_t; 78 79 typedef struct { 80 uint16_t cid; 81 goep_state_t state; 82 bd_addr_t bd_addr; 83 hci_con_handle_t con_handle; 84 uint8_t incoming; 85 uint8_t rfcomm_port; 86 uint16_t l2cap_psm; 87 uint16_t bearer_cid; 88 uint16_t bearer_mtu; 89 uint32_t pbap_supported_features; 90 91 uint8_t obex_opcode; 92 uint32_t obex_connection_id; 93 int obex_connection_id_set; 94 95 btstack_packet_handler_t client_handler; 96 } goep_client_t; 97 98 static goep_client_t _goep_client; 99 static goep_client_t * goep_client = &_goep_client; 100 101 static uint8_t attribute_value[30]; 102 static const unsigned int attribute_value_buffer_size = sizeof(attribute_value); 103 104 static uint8_t goep_packet_buffer[100]; 105 106 #ifdef ENABLE_GOEP_L2CAP 107 static uint8_t ertm_buffer[1000]; 108 static l2cap_ertm_config_t ertm_config = { 109 1, // ertm mandatory 110 2, // max transmit, some tests require > 1 111 2000, 112 12000, 113 512, // l2cap ertm mtu 114 2, 115 2, 116 0, // No FCS 117 }; 118 #endif 119 120 static inline void goep_client_emit_connected_event(goep_client_t * context, uint8_t status){ 121 uint8_t event[15]; 122 int pos = 0; 123 event[pos++] = HCI_EVENT_GOEP_META; 124 pos++; // skip len 125 event[pos++] = GOEP_SUBEVENT_CONNECTION_OPENED; 126 little_endian_store_16(event,pos,context->cid); 127 pos+=2; 128 event[pos++] = status; 129 memcpy(&event[pos], context->bd_addr, 6); 130 pos += 6; 131 little_endian_store_16(event,pos,context->con_handle); 132 pos += 2; 133 event[pos++] = context->incoming; 134 event[1] = pos - 2; 135 if (pos != sizeof(event)) log_error("goep_client_emit_connected_event size %u", pos); 136 context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos); 137 } 138 139 static inline void goep_client_emit_connection_closed_event(goep_client_t * context){ 140 uint8_t event[5]; 141 int pos = 0; 142 event[pos++] = HCI_EVENT_GOEP_META; 143 pos++; // skip len 144 event[pos++] = GOEP_SUBEVENT_CONNECTION_CLOSED; 145 little_endian_store_16(event,pos,context->cid); 146 pos+=2; 147 event[1] = pos - 2; 148 if (pos != sizeof(event)) log_error("goep_client_emit_connection_closed_event size %u", pos); 149 context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos); 150 } 151 152 static inline void goep_client_emit_can_send_now_event(goep_client_t * context){ 153 uint8_t event[5]; 154 int pos = 0; 155 event[pos++] = HCI_EVENT_GOEP_META; 156 pos++; // skip len 157 event[pos++] = GOEP_SUBEVENT_CAN_SEND_NOW; 158 little_endian_store_16(event,pos,context->cid); 159 pos+=2; 160 event[1] = pos - 2; 161 if (pos != sizeof(event)) log_error("goep_client_emit_can_send_now_event size %u", pos); 162 context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos); 163 } 164 165 static void goep_client_handle_connection_opened(goep_client_t * context, uint8_t status, uint16_t mtu){ 166 if (status) { 167 context->state = GOEP_INIT; 168 log_info("goep_client: open failed, status %u", status); 169 } else { 170 context->bearer_mtu = mtu; 171 context->state = GOEP_CONNECTED; 172 log_info("goep_client: connection opened. cid %u, max frame size %u", context->bearer_cid, context->bearer_mtu); 173 } 174 goep_client_emit_connected_event(context, status); 175 } 176 177 static void goep_client_handle_connection_close(goep_client_t * context){ 178 context->state = GOEP_INIT; 179 goep_client_emit_connection_closed_event(context); 180 } 181 182 static void goep_client_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 183 UNUSED(channel); 184 UNUSED(size); 185 goep_client_t * context = goep_client; 186 switch (packet_type){ 187 case HCI_EVENT_PACKET: 188 switch (hci_event_packet_get_type(packet)) { 189 #ifdef ENABLE_GOEP_L2CAP 190 case L2CAP_EVENT_CHANNEL_OPENED: 191 goep_client_handle_connection_opened(context, l2cap_event_channel_opened_get_status(packet), 192 btstack_min(l2cap_event_channel_opened_get_remote_mtu(packet), l2cap_event_channel_opened_get_local_mtu(packet))); 193 return; 194 case L2CAP_EVENT_CAN_SEND_NOW: 195 goep_client_emit_can_send_now_event(context); 196 break; 197 case L2CAP_EVENT_CHANNEL_CLOSED: 198 goep_client_handle_connection_close(context); 199 break; 200 #endif 201 case RFCOMM_EVENT_CHANNEL_OPENED: 202 goep_client_handle_connection_opened(context, rfcomm_event_channel_opened_get_status(packet), rfcomm_event_channel_opened_get_max_frame_size(packet)); 203 return; 204 case RFCOMM_EVENT_CAN_SEND_NOW: 205 goep_client_emit_can_send_now_event(context); 206 break; 207 case RFCOMM_EVENT_CHANNEL_CLOSED: 208 goep_client_handle_connection_close(context); 209 break; 210 default: 211 break; 212 } 213 break; 214 case L2CAP_DATA_PACKET: 215 case RFCOMM_DATA_PACKET: 216 context->client_handler(GOEP_DATA_PACKET, context->cid, packet, size); 217 break; 218 default: 219 break; 220 } 221 } 222 223 static void goep_client_handle_sdp_query_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 224 goep_client_t * context = goep_client; 225 226 UNUSED(packet_type); 227 UNUSED(channel); 228 UNUSED(size); 229 230 des_iterator_t des_list_it; 231 des_iterator_t prot_it; 232 uint8_t status; 233 234 235 switch (hci_event_packet_get_type(packet)){ 236 case SDP_EVENT_QUERY_ATTRIBUTE_VALUE: 237 238 // check if relevant attribute 239 switch(sdp_event_query_attribute_byte_get_attribute_id(packet)){ 240 case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST: 241 case BLUETOOTH_ATTRIBUTE_PBAP_SUPPORTED_FEATURES: 242 #ifdef ENABLE_GOEP_L2CAP 243 case BLUETOOTH_ATTRIBUTE_GOEP_L2CAP_PSM: 244 #endif 245 break; 246 default: 247 return; 248 } 249 250 // warn if attribute too large to fit in our buffer 251 if (sdp_event_query_attribute_byte_get_attribute_length(packet) > attribute_value_buffer_size) { 252 log_error("SDP attribute value size exceeded for attribute %x: available %d, required %d", sdp_event_query_attribute_byte_get_attribute_id(packet), attribute_value_buffer_size, sdp_event_query_attribute_byte_get_attribute_length(packet)); 253 break; 254 } 255 256 // store single byte 257 attribute_value[sdp_event_query_attribute_byte_get_data_offset(packet)] = sdp_event_query_attribute_byte_get_data(packet); 258 259 // wait until value fully received 260 if ((uint16_t)(sdp_event_query_attribute_byte_get_data_offset(packet)+1) != sdp_event_query_attribute_byte_get_attribute_length(packet)) break; 261 262 // process attributes 263 switch(sdp_event_query_attribute_byte_get_attribute_id(packet)) { 264 case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST: 265 for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) { 266 uint8_t *des_element; 267 uint8_t *element; 268 uint32_t uuid; 269 #ifdef ENABLE_GOEP_L2CAP 270 uint16_t l2cap_psm; 271 #endif 272 273 if (des_iterator_get_type(&des_list_it) != DE_DES) continue; 274 275 des_element = des_iterator_get_element(&des_list_it); 276 des_iterator_init(&prot_it, des_element); 277 278 // first element is UUID 279 element = des_iterator_get_element(&prot_it); 280 if (de_get_element_type(element) != DE_UUID) continue; 281 282 uuid = de_get_uuid32(element); 283 des_iterator_next(&prot_it); 284 if (!des_iterator_has_more(&prot_it)) continue; 285 286 // second element is RFCOMM server channel or L2CAP PSM 287 element = des_iterator_get_element(&prot_it); 288 switch (uuid){ 289 #ifdef ENABLE_GOEP_L2CAP 290 case BLUETOOTH_PROTOCOL_L2CAP: 291 if (de_element_get_uint16(element, &l2cap_psm)){ 292 context->l2cap_psm = l2cap_psm; 293 } 294 break; 295 #endif 296 case BLUETOOTH_PROTOCOL_RFCOMM: 297 context->rfcomm_port = element[de_get_header_size(element)]; 298 break; 299 default: 300 break; 301 } 302 } 303 break; 304 #ifdef ENABLE_GOEP_L2CAP 305 case BLUETOOTH_ATTRIBUTE_GOEP_L2CAP_PSM: 306 de_element_get_uint16(attribute_value, &context->l2cap_psm); 307 break; 308 #endif 309 case BLUETOOTH_ATTRIBUTE_PBAP_SUPPORTED_FEATURES: 310 if (de_get_element_type(attribute_value) != DE_UINT) break; 311 if (de_get_size_type(attribute_value) != DE_SIZE_32) break; 312 context->pbap_supported_features = big_endian_read_32(attribute_value, de_get_header_size(attribute_value)); 313 log_info("pbap_supported_features 0x%x", context->pbap_supported_features); 314 break; 315 default: 316 break; 317 } 318 break; 319 320 case SDP_EVENT_QUERY_COMPLETE: 321 status = sdp_event_query_complete_get_status(packet); 322 if (status != ERROR_CODE_SUCCESS){ 323 log_info("GOEP client, SDP query failed 0x%02x", status); 324 context->state = GOEP_INIT; 325 goep_client_emit_connected_event(goep_client, status); 326 break; 327 } 328 if ((context->rfcomm_port == 0) && (context->l2cap_psm == 0)){ 329 log_info("No GOEP RFCOMM or L2CAP server found"); 330 context->state = GOEP_INIT; 331 goep_client_emit_connected_event(goep_client, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); 332 break; 333 } 334 #ifdef ENABLE_GOEP_L2CAP 335 if (context->l2cap_psm){ 336 log_info("Remote GOEP L2CAP PSM: %u", context->l2cap_psm); 337 l2cap_create_ertm_channel(&goep_client_packet_handler, context->bd_addr, context->l2cap_psm, 338 &ertm_config, ertm_buffer, sizeof(ertm_buffer), &context->bearer_cid); 339 return; 340 } 341 #endif 342 log_info("Remote GOEP RFCOMM Server Channel: %u", context->rfcomm_port); 343 rfcomm_create_channel(&goep_client_packet_handler, context->bd_addr, context->rfcomm_port, &context->bearer_cid); 344 } 345 } 346 347 static uint8_t * goep_client_get_outgoing_buffer(goep_client_t * context){ 348 if (context->l2cap_psm){ 349 return goep_packet_buffer; 350 } else { 351 return rfcomm_get_outgoing_buffer(); 352 } 353 } 354 355 static uint16_t goep_client_get_outgoing_buffer_len(goep_client_t * context){ 356 if (context->l2cap_psm){ 357 return sizeof(goep_packet_buffer); 358 } else { 359 return rfcomm_get_max_frame_size(context->bearer_cid); 360 } 361 } 362 363 static void goep_client_packet_init(uint16_t goep_cid, uint8_t opcode){ 364 UNUSED(goep_cid); 365 goep_client_t * context = goep_client; 366 if (context->l2cap_psm){ 367 } else { 368 rfcomm_reserve_packet_buffer(); 369 } 370 // store opcode for parsing of response 371 context->obex_opcode = opcode; 372 } 373 374 void goep_client_init(void){ 375 memset(goep_client, 0, sizeof(goep_client_t)); 376 goep_client->state = GOEP_INIT; 377 goep_client->cid = 1; 378 goep_client->obex_connection_id = OBEX_CONNECTION_ID_INVALID; 379 } 380 381 uint8_t goep_client_create_connection(btstack_packet_handler_t handler, bd_addr_t addr, uint16_t uuid, uint16_t * out_cid){ 382 goep_client_t * context = goep_client; 383 if (context->state != GOEP_INIT) return BTSTACK_MEMORY_ALLOC_FAILED; 384 context->client_handler = handler; 385 context->state = GOEP_W4_SDP; 386 context->l2cap_psm = 0; 387 context->rfcomm_port = 0; 388 context->pbap_supported_features = PBAP_FEATURES_NOT_PRESENT; 389 memcpy(context->bd_addr, addr, 6); 390 sdp_client_query_uuid16(&goep_client_handle_sdp_query_event, context->bd_addr, uuid); 391 *out_cid = context->cid; 392 return 0; 393 } 394 395 uint32_t goep_client_get_pbap_supported_features(uint16_t goep_cid){ 396 UNUSED(goep_cid); 397 goep_client_t * context = goep_client; 398 return context->pbap_supported_features; 399 } 400 401 uint8_t goep_client_disconnect(uint16_t goep_cid){ 402 UNUSED(goep_cid); 403 goep_client_t * context = goep_client; 404 rfcomm_disconnect(context->bearer_cid); 405 return 0; 406 } 407 408 void goep_client_set_connection_id(uint16_t goep_cid, uint32_t connection_id){ 409 UNUSED(goep_cid); 410 goep_client_t * context = goep_client; 411 context->obex_connection_id = connection_id; 412 } 413 414 uint8_t goep_client_get_request_opcode(uint16_t goep_cid){ 415 UNUSED(goep_cid); 416 goep_client_t * context = goep_client; 417 return context->obex_opcode; 418 } 419 420 void goep_client_request_can_send_now(uint16_t goep_cid){ 421 UNUSED(goep_cid); 422 goep_client_t * context = goep_client; 423 if (context->l2cap_psm){ 424 l2cap_request_can_send_now_event(context->bearer_cid); 425 } else { 426 rfcomm_request_can_send_now_event(context->bearer_cid); 427 } 428 } 429 430 void goep_client_request_create_connect(uint16_t goep_cid, uint8_t obex_version_number, uint8_t flags, uint16_t maximum_obex_packet_length){ 431 UNUSED(goep_cid); 432 goep_client_t * context = goep_client; 433 goep_client_packet_init(goep_cid, OBEX_OPCODE_CONNECT); 434 435 // workaround: limit OBEX packet len to L2CAP/RFCOMM MTU to avoid handling of fragemented packets 436 maximum_obex_packet_length = btstack_min(maximum_obex_packet_length, context->bearer_mtu); 437 438 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 439 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 440 obex_message_builder_request_create_connect(buffer, buffer_len, obex_version_number, flags, maximum_obex_packet_length); 441 } 442 443 void goep_client_request_create_get(uint16_t goep_cid){ 444 UNUSED(goep_cid); 445 goep_client_t * context = goep_client; 446 goep_client_packet_init(goep_cid, OBEX_OPCODE_GET | OBEX_OPCODE_FINAL_BIT_MASK); 447 448 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 449 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 450 obex_message_builder_request_create_get(buffer, buffer_len, context->obex_connection_id); 451 } 452 453 void goep_client_request_create_put(uint16_t goep_cid){ 454 UNUSED(goep_cid); 455 goep_client_t * context = goep_client; 456 goep_client_packet_init(goep_cid, OBEX_OPCODE_PUT | OBEX_OPCODE_FINAL_BIT_MASK); 457 458 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 459 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 460 obex_message_builder_request_create_put(buffer, buffer_len, context->obex_connection_id); 461 } 462 463 void goep_client_request_create_set_path(uint16_t goep_cid, uint8_t flags){ 464 UNUSED(goep_cid); 465 goep_client_t * context = goep_client; 466 goep_client_packet_init(goep_cid, OBEX_OPCODE_SETPATH); 467 468 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 469 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 470 obex_message_builder_request_create_set_path(buffer, buffer_len, flags, context->obex_connection_id); 471 } 472 473 void goep_client_request_create_abort(uint16_t goep_cid){ 474 UNUSED(goep_cid); 475 goep_client_t * context = goep_client; 476 goep_client_packet_init(goep_cid, OBEX_OPCODE_ABORT); 477 478 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 479 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 480 obex_message_builder_request_create_abort(buffer, buffer_len, context->obex_connection_id); 481 } 482 483 void goep_client_request_create_disconnect(uint16_t goep_cid){ 484 UNUSED(goep_cid); 485 goep_client_t * context = goep_client; 486 goep_client_packet_init(goep_cid, OBEX_OPCODE_DISCONNECT); 487 488 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 489 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 490 obex_message_builder_request_create_disconnect(buffer, buffer_len, context->obex_connection_id); 491 } 492 493 void goep_client_header_add_byte(uint16_t goep_cid, uint8_t header_type, uint8_t value){ 494 UNUSED(goep_cid); 495 goep_client_t * context = goep_client; 496 497 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 498 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 499 obex_message_builder_header_add_byte(buffer, buffer_len, header_type, value); 500 } 501 502 void goep_client_header_add_word(uint16_t goep_cid, uint8_t header_type, uint32_t value){ 503 UNUSED(goep_cid); 504 goep_client_t * context = goep_client; 505 506 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 507 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 508 obex_message_builder_header_add_word(buffer, buffer_len, header_type, value); 509 } 510 511 void goep_client_header_add_variable(uint16_t goep_cid, uint8_t header_type, const uint8_t * header_data, uint16_t header_data_length){ 512 UNUSED(goep_cid); 513 goep_client_t * context = goep_client; 514 515 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 516 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 517 obex_message_builder_header_add_variable(buffer, buffer_len, header_type, header_data, header_data_length); 518 } 519 520 void goep_client_header_add_srm_enable(uint16_t goep_cid){ 521 UNUSED(goep_cid); 522 goep_client_t * context = goep_client; 523 524 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 525 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 526 obex_message_builder_header_add_srm_enable(buffer, buffer_len); 527 } 528 529 void goep_client_header_add_target(uint16_t goep_cid, const uint8_t * target, uint16_t length){ 530 UNUSED(goep_cid); 531 goep_client_t * context = goep_client; 532 533 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 534 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 535 obex_message_builder_header_add_target(buffer, buffer_len, target, length); 536 } 537 538 void goep_client_header_add_application_parameters(uint16_t goep_cid, const uint8_t * data, uint16_t length){ 539 UNUSED(goep_cid); 540 goep_client_t * context = goep_client; 541 542 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 543 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 544 obex_message_builder_header_add_application_parameters(buffer, buffer_len, data, length); 545 } 546 547 void goep_client_header_add_challenge_response(uint16_t goep_cid, const uint8_t * data, uint16_t length){ 548 UNUSED(goep_cid); 549 goep_client_t * context = goep_client; 550 551 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 552 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 553 obex_message_builder_header_add_challenge_response(buffer, buffer_len, data, length); 554 } 555 556 void goep_client_body_add_static(uint16_t goep_cid, const uint8_t * data, uint32_t length){ 557 UNUSED(goep_cid); 558 goep_client_t * context = goep_client; 559 560 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 561 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 562 obex_message_builder_body_add_static(buffer, buffer_len, data, length); 563 } 564 565 void goep_client_header_add_name(uint16_t goep_cid, const char * name){ 566 UNUSED(goep_cid); 567 goep_client_t * context = goep_client; 568 569 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 570 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 571 obex_message_builder_header_add_name(buffer, buffer_len, name); 572 } 573 574 void goep_client_header_add_type(uint16_t goep_cid, const char * type){ 575 UNUSED(goep_cid); 576 goep_client_t * context = goep_client; 577 578 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 579 uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context); 580 obex_message_builder_header_add_type(buffer, buffer_len, type); 581 } 582 583 int goep_client_execute(uint16_t goep_cid){ 584 UNUSED(goep_cid); 585 goep_client_t * context = goep_client; 586 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 587 uint16_t pos = big_endian_read_16(buffer, 1); 588 if (context->l2cap_psm){ 589 return l2cap_send(context->bearer_cid, buffer, pos); 590 } else { 591 return rfcomm_send_prepared(context->bearer_cid, pos); 592 } 593 } 594 595