l2cap.c (71e8bc1a66f3c6a7d7094be3b044a244990e9d92) l2cap.c (de5414a240cf093ed33d624e9cc700c33dcc1a05)
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

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

1383 // notify client
1384 l2cap_handle_channel_open_failed(channel, L2CAP_CONNECTION_RESPONSE_RESULT_RTX_TIMEOUT);
1385
1386 // discard channel
1387 btstack_linked_list_remove(&l2cap_channels, (btstack_linked_item_t *) channel);
1388 l2cap_free_channel_entry(channel);
1389}
1390
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

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

1383 // notify client
1384 l2cap_handle_channel_open_failed(channel, L2CAP_CONNECTION_RESPONSE_RESULT_RTX_TIMEOUT);
1385
1386 // discard channel
1387 btstack_linked_list_remove(&l2cap_channels, (btstack_linked_item_t *) channel);
1388 l2cap_free_channel_entry(channel);
1389}
1390
1391static uint8_t l2cap_classic_packet_boundary_flag(void){
1392 return hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
1393}
1391#endif
1392
1393#ifdef L2CAP_USES_CHANNELS
1394static void l2cap_stop_rtx(l2cap_channel_t * channel){
1395 log_info("l2cap_stop_rtx for local cid 0x%02x", channel->local_cid);
1396 btstack_run_loop_remove_timer(&channel->rtx);
1397}
1398#endif

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

1410}
1411
1412#ifdef L2CAP_USES_CREDIT_BASED_CHANNELS
1413static int l2cap_send_general_signaling_packet(hci_con_handle_t handle, uint16_t signaling_cid, L2CAP_SIGNALING_COMMANDS cmd, int identifier, ...){
1414 va_list argptr;
1415 va_start(argptr, identifier);
1416 uint8_t pb_flags = 0x00;
1417#ifdef ENABLE_CLASSIC
1394#endif
1395
1396#ifdef L2CAP_USES_CHANNELS
1397static void l2cap_stop_rtx(l2cap_channel_t * channel){
1398 log_info("l2cap_stop_rtx for local cid 0x%02x", channel->local_cid);
1399 btstack_run_loop_remove_timer(&channel->rtx);
1400}
1401#endif

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

1413}
1414
1415#ifdef L2CAP_USES_CREDIT_BASED_CHANNELS
1416static int l2cap_send_general_signaling_packet(hci_con_handle_t handle, uint16_t signaling_cid, L2CAP_SIGNALING_COMMANDS cmd, int identifier, ...){
1417 va_list argptr;
1418 va_start(argptr, identifier);
1419 uint8_t pb_flags = 0x00;
1420#ifdef ENABLE_CLASSIC
1418 if ((signaling_cid == L2CAP_CID_SIGNALING) && (!hci_non_flushable_packet_boundary_flag_supported())){
1419 pb_flags = 0x02;
1421 if (signaling_cid == L2CAP_CID_SIGNALING){
1422 pb_flags = l2cap_classic_packet_boundary_flag();
1420 }
1421#endif
1422uint8_t result = l2cap_send_signaling_packet(handle, pb_flags, signaling_cid, cmd, identifier, argptr);
1423 va_end(argptr);
1424 return result;
1425}
1426#endif
1427

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

1449
1450static int l2cap_security_level_0_allowed_for_PSM(uint16_t psm){
1451 return (psm == BLUETOOTH_PSM_SDP) && (!l2cap_require_security_level2_for_outgoing_sdp);
1452}
1453
1454static int l2cap_send_classic_signaling_packet(hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, int identifier, ...){
1455 va_list argptr;
1456 va_start(argptr, identifier);
1423 }
1424#endif
1425uint8_t result = l2cap_send_signaling_packet(handle, pb_flags, signaling_cid, cmd, identifier, argptr);
1426 va_end(argptr);
1427 return result;
1428}
1429#endif
1430

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

1452
1453static int l2cap_security_level_0_allowed_for_PSM(uint16_t psm){
1454 return (psm == BLUETOOTH_PSM_SDP) && (!l2cap_require_security_level2_for_outgoing_sdp);
1455}
1456
1457static int l2cap_send_classic_signaling_packet(hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, int identifier, ...){
1458 va_list argptr;
1459 va_start(argptr, identifier);
1457 uint8_t pb_flags = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
1458 uint8_t result = l2cap_send_signaling_packet(handle, pb_flags, L2CAP_CID_SIGNALING, cmd, identifier, argptr);
1460 uint8_t pb_flag = l2cap_classic_packet_boundary_flag();
1461 uint8_t result = l2cap_send_signaling_packet(handle, pb_flag, L2CAP_CID_SIGNALING, cmd, identifier, argptr);
1459 va_end(argptr);
1460 return result;
1461}
1462
1463// assumption - only on Classic connections
1464// cannot be used for L2CAP ERTM
1465uint8_t l2cap_send_prepared(uint16_t local_cid, uint16_t len){
1466

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

1487#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
1488 if (channel->mode == L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION && channel->fcs_option){
1489 fcs_size = 2;
1490 }
1491#endif
1492
1493 // set non-flushable packet boundary flag if supported on Controller
1494 uint8_t *acl_buffer = hci_get_outgoing_packet_buffer();
1462 va_end(argptr);
1463 return result;
1464}
1465
1466// assumption - only on Classic connections
1467// cannot be used for L2CAP ERTM
1468uint8_t l2cap_send_prepared(uint16_t local_cid, uint16_t len){
1469

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

1490#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
1491 if (channel->mode == L2CAP_CHANNEL_MODE_ENHANCED_RETRANSMISSION && channel->fcs_option){
1492 fcs_size = 2;
1493 }
1494#endif
1495
1496 // set non-flushable packet boundary flag if supported on Controller
1497 uint8_t *acl_buffer = hci_get_outgoing_packet_buffer();
1495 uint8_t packet_boundary_flag = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
1498 uint8_t packet_boundary_flag = l2cap_classic_packet_boundary_flag();
1496 l2cap_setup_header(acl_buffer, channel->con_handle, packet_boundary_flag, channel->remote_cid, len + fcs_size);
1497
1498#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
1499 if (fcs_size){
1500 // calculate FCS over l2cap data
1501 uint16_t fcs = crc16_calc(acl_buffer + 4, 4 + len);
1502 log_info("I-Frame: fcs 0x%04x", fcs);
1503 little_endian_store_16(acl_buffer, 8 + len, fcs);

--- 4048 unchanged lines hidden ---
1499 l2cap_setup_header(acl_buffer, channel->con_handle, packet_boundary_flag, channel->remote_cid, len + fcs_size);
1500
1501#ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
1502 if (fcs_size){
1503 // calculate FCS over l2cap data
1504 uint16_t fcs = crc16_calc(acl_buffer + 4, 4 + len);
1505 log_info("I-Frame: fcs 0x%04x", fcs);
1506 little_endian_store_16(acl_buffer, 8 + len, fcs);

--- 4048 unchanged lines hidden ---