l2cap_signaling.c (7907f06931c075b55e3402fa469abbe35eebee25) l2cap_signaling.c (f8fbdce0c5067e7e7edd3a29934b1f9b79c8ff2d)
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

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

85 return source_cid++;
86}
87
88static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_handle_t handle, uint16_t cid, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
89
90 int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
91
92 // 0 - Connection handle : PB=pb : BC=00
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

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

85 return source_cid++;
86}
87
88static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_handle_t handle, uint16_t cid, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
89
90 int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
91
92 // 0 - Connection handle : PB=pb : BC=00
93 bt_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
93 little_endian_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
94 // 6 - L2CAP channel = 1
94 // 6 - L2CAP channel = 1
95 bt_store_16(acl_buffer, 6, cid);
95 little_endian_store_16(acl_buffer, 6, cid);
96 // 8 - Code
97 acl_buffer[8] = cmd;
98 // 9 - id (!= 0 sequentially)
99 acl_buffer[9] = identifier;
100
101 // 12 - L2CAP signaling parameters
102 uint16_t pos = 12;
103 // skip AMP commands

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

130 format++;
131 };
132 va_end(argptr);
133
134 // Fill in various length fields: it's the number of bytes following for ACL lenght and l2cap parameter length
135 // - the l2cap payload length is counted after the following channel id (only payload)
136
137 // 2 - ACL length
96 // 8 - Code
97 acl_buffer[8] = cmd;
98 // 9 - id (!= 0 sequentially)
99 acl_buffer[9] = identifier;
100
101 // 12 - L2CAP signaling parameters
102 uint16_t pos = 12;
103 // skip AMP commands

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

130 format++;
131 };
132 va_end(argptr);
133
134 // Fill in various length fields: it's the number of bytes following for ACL lenght and l2cap parameter length
135 // - the l2cap payload length is counted after the following channel id (only payload)
136
137 // 2 - ACL length
138 bt_store_16(acl_buffer, 2, pos - 4);
138 little_endian_store_16(acl_buffer, 2, pos - 4);
139 // 4 - L2CAP packet length
139 // 4 - L2CAP packet length
140 bt_store_16(acl_buffer, 4, pos - 6 - 2);
140 little_endian_store_16(acl_buffer, 4, pos - 6 - 2);
141 // 10 - L2CAP signaling parameter length
141 // 10 - L2CAP signaling parameter length
142 bt_store_16(acl_buffer, 10, pos - 12);
142 little_endian_store_16(acl_buffer, 10, pos - 12);
143
144 return pos;
145}
146
147uint16_t l2cap_create_signaling_classic(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
148 return l2cap_create_signaling_internal(acl_buffer, handle, 1, cmd, identifier, argptr);
149}
150
151#ifdef ENABLE_BLE
152uint16_t l2cap_create_signaling_le(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
153 return l2cap_create_signaling_internal(acl_buffer, handle, 5, cmd, identifier, argptr);
154}
155#endif
143
144 return pos;
145}
146
147uint16_t l2cap_create_signaling_classic(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
148 return l2cap_create_signaling_internal(acl_buffer, handle, 1, cmd, identifier, argptr);
149}
150
151#ifdef ENABLE_BLE
152uint16_t l2cap_create_signaling_le(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
153 return l2cap_create_signaling_internal(acl_buffer, handle, 5, cmd, identifier, argptr);
154}
155#endif