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.h" 53 #include "classic/obex_iterator.h" 54 #include "classic/rfcomm.h" 55 #include "classic/sdp_client.h" 56 #include "classic/sdp_util.h" 57 #include "l2cap.h" 58 59 //------------------------------------------------------------------------------------------------------------ 60 // goep_client.c 61 // 62 63 // #define ENABLE_GOEP_L2CAP 64 65 #ifdef ENABLE_GOEP_L2CAP 66 #ifndef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE 67 #error "ENABLE_GOEP_L2CAP requires ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE. Please enable ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE or disable ENABLE_GOEP_L2CAP" 68 #endif 69 #endif 70 71 typedef enum { 72 GOEP_INIT, 73 GOEP_W4_SDP, 74 GOEP_W4_CONNECTION, 75 GOEP_CONNECTED, 76 } goep_state_t; 77 78 typedef struct { 79 uint16_t cid; 80 goep_state_t state; 81 bd_addr_t bd_addr; 82 hci_con_handle_t con_handle; 83 uint8_t incoming; 84 uint8_t rfcomm_port; 85 uint16_t l2cap_psm; 86 uint16_t bearer_cid; 87 uint16_t bearer_mtu; 88 uint32_t pbap_supported_features; 89 90 uint8_t obex_opcode; 91 uint32_t obex_connection_id; 92 int obex_connection_id_set; 93 94 btstack_packet_handler_t client_handler; 95 } goep_client_t; 96 97 static goep_client_t _goep_client; 98 static goep_client_t * goep_client = &_goep_client; 99 100 static uint8_t attribute_value[30]; 101 static const unsigned int attribute_value_buffer_size = sizeof(attribute_value); 102 103 static uint8_t goep_packet_buffer[100]; 104 105 #ifdef ENABLE_GOEP_L2CAP 106 static uint8_t ertm_buffer[1000]; 107 static l2cap_ertm_config_t ertm_config = { 108 1, // ertm mandatory 109 2, // max transmit, some tests require > 1 110 2000, 111 12000, 112 512, // l2cap ertm mtu 113 2, 114 2, 115 }; 116 #endif 117 118 static inline void goep_client_emit_connected_event(goep_client_t * context, uint8_t status){ 119 uint8_t event[15]; 120 int pos = 0; 121 event[pos++] = HCI_EVENT_GOEP_META; 122 pos++; // skip len 123 event[pos++] = GOEP_SUBEVENT_CONNECTION_OPENED; 124 little_endian_store_16(event,pos,context->cid); 125 pos+=2; 126 event[pos++] = status; 127 memcpy(&event[pos], context->bd_addr, 6); 128 pos += 6; 129 little_endian_store_16(event,pos,context->con_handle); 130 pos += 2; 131 event[pos++] = context->incoming; 132 event[1] = pos - 2; 133 if (pos != sizeof(event)) log_error("goep_client_emit_connected_event size %u", pos); 134 context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos); 135 } 136 137 static inline void goep_client_emit_connection_closed_event(goep_client_t * context){ 138 uint8_t event[5]; 139 int pos = 0; 140 event[pos++] = HCI_EVENT_GOEP_META; 141 pos++; // skip len 142 event[pos++] = GOEP_SUBEVENT_CONNECTION_CLOSED; 143 little_endian_store_16(event,pos,context->cid); 144 pos+=2; 145 event[1] = pos - 2; 146 if (pos != sizeof(event)) log_error("goep_client_emit_connection_closed_event size %u", pos); 147 context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos); 148 } 149 150 static inline void goep_client_emit_can_send_now_event(goep_client_t * context){ 151 uint8_t event[5]; 152 int pos = 0; 153 event[pos++] = HCI_EVENT_GOEP_META; 154 pos++; // skip len 155 event[pos++] = GOEP_SUBEVENT_CAN_SEND_NOW; 156 little_endian_store_16(event,pos,context->cid); 157 pos+=2; 158 event[1] = pos - 2; 159 if (pos != sizeof(event)) log_error("goep_client_emit_can_send_now_event size %u", pos); 160 context->client_handler(HCI_EVENT_PACKET, context->cid, &event[0], pos); 161 } 162 163 static void goep_client_handle_connection_opened(goep_client_t * context, uint8_t status, uint16_t mtu){ 164 if (status) { 165 context->state = GOEP_INIT; 166 log_info("goep_client: open failed, status %u", status); 167 } else { 168 context->bearer_mtu = mtu; 169 context->state = GOEP_CONNECTED; 170 log_info("goep_client: connection opened. cid %u, max frame size %u", context->bearer_cid, context->bearer_mtu); 171 } 172 goep_client_emit_connected_event(context, status); 173 } 174 175 static void goep_client_handle_connection_close(goep_client_t * context){ 176 context->state = GOEP_INIT; 177 goep_client_emit_connection_closed_event(context); 178 } 179 180 static void goep_client_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 181 UNUSED(channel); 182 UNUSED(size); 183 goep_client_t * context = goep_client; 184 switch (packet_type){ 185 case HCI_EVENT_PACKET: 186 switch (hci_event_packet_get_type(packet)) { 187 #ifdef ENABLE_GOEP_L2CAP 188 case L2CAP_EVENT_CHANNEL_OPENED: 189 goep_client_handle_connection_opened(context, l2cap_event_channel_opened_get_status(packet), 190 btstack_min(l2cap_event_channel_opened_get_remote_mtu(packet), l2cap_event_channel_opened_get_local_mtu(packet))); 191 return; 192 case L2CAP_EVENT_CAN_SEND_NOW: 193 goep_client_emit_can_send_now_event(context); 194 break; 195 case L2CAP_EVENT_CHANNEL_CLOSED: 196 goep_client_handle_connection_close(context); 197 break; 198 #endif 199 case RFCOMM_EVENT_CHANNEL_OPENED: 200 goep_client_handle_connection_opened(context, rfcomm_event_channel_opened_get_status(packet), rfcomm_event_channel_opened_get_max_frame_size(packet)); 201 return; 202 case RFCOMM_EVENT_CAN_SEND_NOW: 203 goep_client_emit_can_send_now_event(context); 204 break; 205 case RFCOMM_EVENT_CHANNEL_CLOSED: 206 goep_client_handle_connection_close(context); 207 break; 208 default: 209 break; 210 } 211 break; 212 case L2CAP_DATA_PACKET: 213 case RFCOMM_DATA_PACKET: 214 context->client_handler(GOEP_DATA_PACKET, context->cid, packet, size); 215 break; 216 default: 217 break; 218 } 219 } 220 221 static void goep_client_handle_sdp_query_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 222 goep_client_t * context = goep_client; 223 224 UNUSED(packet_type); 225 UNUSED(channel); 226 UNUSED(size); 227 228 des_iterator_t des_list_it; 229 des_iterator_t prot_it; 230 uint8_t status; 231 232 233 switch (hci_event_packet_get_type(packet)){ 234 case SDP_EVENT_QUERY_ATTRIBUTE_VALUE: 235 236 // check if relevant attribute 237 switch(sdp_event_query_attribute_byte_get_attribute_id(packet)){ 238 case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST: 239 case BLUETOOTH_ATTRIBUTE_PBAP_SUPPORTED_FEATURES: 240 #ifdef ENABLE_GOEP_L2CAP 241 case BLUETOOTH_ATTRIBUTE_GOEP_L2CAP_PSM: 242 #endif 243 break; 244 default: 245 return; 246 } 247 248 // warn if attribute too large to fit in our buffer 249 if (sdp_event_query_attribute_byte_get_attribute_length(packet) > attribute_value_buffer_size) { 250 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)); 251 break; 252 } 253 254 // store single byte 255 attribute_value[sdp_event_query_attribute_byte_get_data_offset(packet)] = sdp_event_query_attribute_byte_get_data(packet); 256 257 // wait until value fully received 258 if ((uint16_t)(sdp_event_query_attribute_byte_get_data_offset(packet)+1) != sdp_event_query_attribute_byte_get_attribute_length(packet)) break; 259 260 // process attributes 261 switch(sdp_event_query_attribute_byte_get_attribute_id(packet)) { 262 case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST: 263 for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) { 264 uint8_t *des_element; 265 uint8_t *element; 266 uint32_t uuid; 267 #ifdef ENABLE_GOEP_L2CAP 268 uint16_t l2cap_psm; 269 #endif 270 271 if (des_iterator_get_type(&des_list_it) != DE_DES) continue; 272 273 des_element = des_iterator_get_element(&des_list_it); 274 des_iterator_init(&prot_it, des_element); 275 276 // first element is UUID 277 element = des_iterator_get_element(&prot_it); 278 if (de_get_element_type(element) != DE_UUID) continue; 279 280 uuid = de_get_uuid32(element); 281 des_iterator_next(&prot_it); 282 if (!des_iterator_has_more(&prot_it)) continue; 283 284 // second element is RFCOMM server channel or L2CAP PSM 285 element = des_iterator_get_element(&prot_it); 286 switch (uuid){ 287 #ifdef ENABLE_GOEP_L2CAP 288 case BLUETOOTH_PROTOCOL_L2CAP: 289 if (de_element_get_uint16(element, &l2cap_psm)){ 290 context->l2cap_psm = l2cap_psm; 291 } 292 break; 293 #endif 294 case BLUETOOTH_PROTOCOL_RFCOMM: 295 context->rfcomm_port = element[de_get_header_size(element)]; 296 break; 297 default: 298 break; 299 } 300 } 301 break; 302 #ifdef ENABLE_GOEP_L2CAP 303 case BLUETOOTH_ATTRIBUTE_GOEP_L2CAP_PSM: 304 de_element_get_uint16(attribute_value, &context->l2cap_psm); 305 break; 306 #endif 307 case BLUETOOTH_ATTRIBUTE_PBAP_SUPPORTED_FEATURES: 308 if (de_get_element_type(attribute_value) != DE_UINT) break; 309 if (de_get_size_type(attribute_value) != DE_SIZE_32) break; 310 context->pbap_supported_features = big_endian_read_32(attribute_value, de_get_header_size(attribute_value)); 311 log_info("pbap_supported_features 0x%x", context->pbap_supported_features); 312 break; 313 default: 314 break; 315 } 316 break; 317 318 case SDP_EVENT_QUERY_COMPLETE: 319 status = sdp_event_query_complete_get_status(packet); 320 if (status != ERROR_CODE_SUCCESS){ 321 log_info("GOEP client, SDP query failed 0x%02x", status); 322 context->state = GOEP_INIT; 323 goep_client_emit_connected_event(goep_client, status); 324 break; 325 } 326 if (context->rfcomm_port == 0 && context->l2cap_psm == 0){ 327 log_info("No GOEP RFCOMM or L2CAP server found"); 328 context->state = GOEP_INIT; 329 goep_client_emit_connected_event(goep_client, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); 330 break; 331 } 332 #ifdef ENABLE_GOEP_L2CAP 333 if (context->l2cap_psm){ 334 log_info("Remote GOEP L2CAP PSM: %u", context->l2cap_psm); 335 l2cap_create_ertm_channel(&goep_client_packet_handler, context->bd_addr, context->l2cap_psm, 336 &ertm_config, ertm_buffer, sizeof(ertm_buffer), &context->bearer_cid); 337 return; 338 } 339 #endif 340 log_info("Remote GOEP RFCOMM Server Channel: %u", context->rfcomm_port); 341 rfcomm_create_channel(&goep_client_packet_handler, context->bd_addr, context->rfcomm_port, &context->bearer_cid); 342 } 343 } 344 345 static uint8_t * goep_client_get_outgoing_buffer(goep_client_t * context){ 346 if (context->l2cap_psm){ 347 return goep_packet_buffer; 348 } else { 349 return rfcomm_get_outgoing_buffer(); 350 } 351 } 352 353 static void goep_client_packet_append(const uint8_t * data, uint16_t len){ 354 goep_client_t * context = goep_client; 355 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 356 uint16_t pos = big_endian_read_16(buffer, 1); 357 memcpy(&buffer[pos], data, len); 358 pos += len; 359 big_endian_store_16(buffer, 1, pos); 360 } 361 362 static void goep_client_packet_init(uint16_t goep_cid, uint8_t opcode){ 363 UNUSED(goep_cid); 364 goep_client_t * context = goep_client; 365 if (context->l2cap_psm){ 366 } else { 367 rfcomm_reserve_packet_buffer(); 368 } 369 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 370 buffer[0] = opcode; 371 big_endian_store_16(buffer, 1, 3); 372 // store opcode for parsing of response 373 context->obex_opcode = opcode; 374 } 375 376 static void goep_client_packet_add_connection_id(uint16_t goep_cid){ 377 UNUSED(goep_cid); 378 goep_client_t * context = goep_client; 379 // add connection_id header if set, must be first header if used 380 if (context->obex_connection_id != OBEX_CONNECTION_ID_INVALID){ 381 goep_client_add_word_header(goep_cid, OBEX_HEADER_CONNECTION_ID, context->obex_connection_id); 382 } 383 } 384 385 void goep_client_init(void){ 386 memset(goep_client, 0, sizeof(goep_client_t)); 387 goep_client->state = GOEP_INIT; 388 goep_client->cid = 1; 389 goep_client->obex_connection_id = OBEX_CONNECTION_ID_INVALID; 390 } 391 392 uint8_t goep_client_create_connection(btstack_packet_handler_t handler, bd_addr_t addr, uint16_t uuid, uint16_t * out_cid){ 393 goep_client_t * context = goep_client; 394 if (context->state != GOEP_INIT) return BTSTACK_MEMORY_ALLOC_FAILED; 395 context->client_handler = handler; 396 context->state = GOEP_W4_SDP; 397 context->l2cap_psm = 0; 398 context->rfcomm_port = 0; 399 context->pbap_supported_features = PBAP_FEATURES_NOT_PRESENT; 400 memcpy(context->bd_addr, addr, 6); 401 sdp_client_query_uuid16(&goep_client_handle_sdp_query_event, context->bd_addr, uuid); 402 *out_cid = context->cid; 403 return 0; 404 } 405 406 uint32_t goep_client_get_pbap_supported_features(uint16_t goep_cid){ 407 UNUSED(goep_cid); 408 goep_client_t * context = goep_client; 409 return context->pbap_supported_features; 410 } 411 412 uint8_t goep_client_disconnect(uint16_t goep_cid){ 413 UNUSED(goep_cid); 414 goep_client_t * context = goep_client; 415 rfcomm_disconnect(context->bearer_cid); 416 return 0; 417 } 418 419 void goep_client_set_connection_id(uint16_t goep_cid, uint32_t connection_id){ 420 UNUSED(goep_cid); 421 goep_client_t * context = goep_client; 422 context->obex_connection_id = connection_id; 423 } 424 425 uint8_t goep_client_get_request_opcode(uint16_t goep_cid){ 426 UNUSED(goep_cid); 427 goep_client_t * context = goep_client; 428 return context->obex_opcode; 429 } 430 431 void goep_client_request_can_send_now(uint16_t goep_cid){ 432 UNUSED(goep_cid); 433 goep_client_t * context = goep_client; 434 if (context->l2cap_psm){ 435 l2cap_request_can_send_now_event(context->bearer_cid); 436 } else { 437 rfcomm_request_can_send_now_event(context->bearer_cid); 438 } 439 } 440 441 void goep_client_create_connect_request(uint16_t goep_cid, uint8_t obex_version_number, uint8_t flags, uint16_t maximum_obex_packet_length){ 442 UNUSED(goep_cid); 443 goep_client_t * context = goep_client; 444 goep_client_packet_init(goep_cid, OBEX_OPCODE_CONNECT); 445 uint8_t fields[4]; 446 fields[0] = obex_version_number; 447 fields[1] = flags; 448 // workaround: limit OBEX packet len to L2CAP/RFCOMM MTU to avoid handling of fragemented packets 449 maximum_obex_packet_length = btstack_min(maximum_obex_packet_length, context->bearer_mtu); 450 big_endian_store_16(fields, 2, maximum_obex_packet_length); 451 goep_client_packet_append(&fields[0], sizeof(fields)); 452 } 453 454 void goep_client_create_get_request(uint16_t goep_cid){ 455 goep_client_packet_init(goep_cid, OBEX_OPCODE_GET | OBEX_OPCODE_FINAL_BIT_MASK); 456 goep_client_packet_add_connection_id(goep_cid); 457 } 458 459 void goep_client_create_set_path_request(uint16_t goep_cid, uint8_t flags){ 460 UNUSED(goep_cid); 461 goep_client_packet_init(goep_cid, OBEX_OPCODE_SETPATH); 462 uint8_t fields[2]; 463 fields[0] = flags; 464 fields[1] = 0; // reserved 465 goep_client_packet_append(&fields[0], sizeof(fields)); 466 goep_client_packet_add_connection_id(goep_cid); 467 } 468 469 void goep_client_create_abort_request(uint16_t goep_cid){ 470 goep_client_packet_init(goep_cid, OBEX_OPCODE_ABORT); 471 goep_client_packet_add_connection_id(goep_cid); 472 } 473 474 void goep_client_create_disconnect_request(uint16_t goep_cid){ 475 UNUSED(goep_cid); 476 goep_client_packet_init(goep_cid, OBEX_OPCODE_DISCONNECT); 477 goep_client_packet_add_connection_id(goep_cid); 478 } 479 480 void goep_client_add_variable_header(uint16_t goep_cid, uint8_t header_type, uint16_t header_data_length, const uint8_t * header_data){ 481 UNUSED(goep_cid); 482 uint8_t header[3]; 483 header[0] = header_type; 484 big_endian_store_16(header, 1, sizeof(header) + header_data_length); 485 goep_client_packet_append(&header[0], sizeof(header)); 486 goep_client_packet_append(header_data, header_data_length); 487 } 488 489 void goep_client_add_byte_header(uint16_t goep_cid, uint8_t header_type, uint8_t value){ 490 UNUSED(goep_cid); 491 uint8_t header[2]; 492 header[0] = header_type; 493 header[1] = value; 494 goep_client_packet_append(&header[0], sizeof(header)); 495 } 496 497 void goep_client_add_word_header(uint16_t goep_cid, uint8_t header_type, uint32_t value){ 498 UNUSED(goep_cid); 499 uint8_t header[5]; 500 header[0] = header_type; 501 big_endian_store_32(header, 1, value); 502 goep_client_packet_append(&header[0], sizeof(header)); 503 } 504 505 void goep_client_add_header_srm_enable(uint16_t goep_cid){ 506 goep_client_add_byte_header(goep_cid, OBEX_HEADER_SINGLE_RESPONSE_MODE, OBEX_SRM_ENABLE); 507 } 508 509 void goep_client_add_header_target(uint16_t goep_cid, uint16_t length, const uint8_t * target){ 510 goep_client_add_variable_header(goep_cid, OBEX_HEADER_TARGET, length, target); 511 } 512 513 void goep_client_add_header_application_parameters(uint16_t goep_cid, uint16_t length, const uint8_t * data){ 514 goep_client_add_variable_header(goep_cid, OBEX_HEADER_APPLICATION_PARAMETERS, length, data); 515 } 516 517 void goep_client_add_header_challenge_response(uint16_t goep_cid, uint16_t length, const uint8_t * data){ 518 goep_client_add_variable_header(goep_cid, OBEX_HEADER_AUTHENTICATION_RESPONSE, length, data); 519 } 520 521 void goep_client_add_header_name(uint16_t goep_cid, const char * name){ 522 UNUSED(goep_cid); 523 goep_client_t * context = goep_client; 524 int len = strlen(name); 525 if (len) { 526 // empty string does not have trailing \0 527 len++; 528 } 529 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 530 uint16_t pos = big_endian_read_16(buffer, 1); 531 buffer[pos++] = OBEX_HEADER_NAME; 532 big_endian_store_16(buffer, pos, 1 + 2 + len*2); 533 pos += 2; 534 int i; 535 // @note name[len] == 0 536 for (i = 0 ; i < len ; i++){ 537 buffer[pos++] = 0; 538 buffer[pos++] = *name++; 539 } 540 big_endian_store_16(buffer, 1, pos); 541 } 542 543 void goep_client_add_header_type(uint16_t goep_cid, const char * type){ 544 UNUSED(goep_cid); 545 uint8_t header[3]; 546 header[0] = OBEX_HEADER_TYPE; 547 int len_incl_zero = strlen(type) + 1; 548 big_endian_store_16(header, 1, 1 + 2 + len_incl_zero); 549 goep_client_packet_append(&header[0], sizeof(header)); 550 goep_client_packet_append((const uint8_t*)type, len_incl_zero); 551 } 552 553 int goep_client_execute(uint16_t goep_cid){ 554 UNUSED(goep_cid); 555 goep_client_t * context = goep_client; 556 uint8_t * buffer = goep_client_get_outgoing_buffer(context); 557 uint16_t pos = big_endian_read_16(buffer, 1); 558 if (context->l2cap_psm){ 559 return l2cap_send(context->bearer_cid, buffer, pos); 560 } else { 561 return rfcomm_send_prepared(context->bearer_cid, pos); 562 } 563 } 564