l2cap_signaling.c (8334d3d848d4b982e94c50bb19c1186089449d05) l2cap_signaling.c (2a9f55d6f76951ae5a88bcea52327be7ae5369f7)
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

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

45
46#include "l2cap_signaling.h"
47#include "btstack_config.h"
48#include "btstack_debug.h"
49#include "hci.h"
50
51#include <string.h>
52
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

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

45
46#include "l2cap_signaling.h"
47#include "btstack_config.h"
48#include "btstack_debug.h"
49#include "hci.h"
50
51#include <string.h>
52
53static 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){
53static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_handle_t handle, bool is_classic, uint16_t cid, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
54
55 static const char *l2cap_signaling_commands_format[] = {
56 "2D", // 0x01 command reject: reason {cmd not understood (0), sig MTU exceeded (2:max sig MTU), invalid CID (4:req CID)}, data len, data
57 "22", // 0x02 connection request: PSM, Source CID
58 "2222", // 0x03 connection response: Dest CID, Source CID, Result, Status
59 "22D", // 0x04 config request: Dest CID, Flags, Configuration options
60 "222D", // 0x05 config response: Source CID, Flags, Result, Configuration options
61 "22", // 0x06 disconection request: Dest CID, Source CID

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

84 if ((cmd > 0) && (cmd <= num_l2cap_commands)) {
85 format = l2cap_signaling_commands_format[cmd-1];
86 }
87 if (!format){
88 log_error("l2cap_create_signaling_internal: invalid command id 0x%02x", cmd);
89 return 0;
90 }
91
54
55 static const char *l2cap_signaling_commands_format[] = {
56 "2D", // 0x01 command reject: reason {cmd not understood (0), sig MTU exceeded (2:max sig MTU), invalid CID (4:req CID)}, data len, data
57 "22", // 0x02 connection request: PSM, Source CID
58 "2222", // 0x03 connection response: Dest CID, Source CID, Result, Status
59 "22D", // 0x04 config request: Dest CID, Flags, Configuration options
60 "222D", // 0x05 config response: Source CID, Flags, Result, Configuration options
61 "22", // 0x06 disconection request: Dest CID, Source CID

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

84 if ((cmd > 0) && (cmd <= num_l2cap_commands)) {
85 format = l2cap_signaling_commands_format[cmd-1];
86 }
87 if (!format){
88 log_error("l2cap_create_signaling_internal: invalid command id 0x%02x", cmd);
89 return 0;
90 }
91
92 int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
92 int pb = 0x00; // First non-automatically-flushable packet of a higher layer message
93#ifdef ENABLE_CLASSIC
94 if (is_classic){
95 pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
96 }
97#endif
93
94 // 0 - Connection handle : PB=pb : BC=00
95 little_endian_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
96 // 6 - L2CAP channel = 1
97 little_endian_store_16(acl_buffer, 6, cid);
98 // 8 - Code
99 acl_buffer[8] = cmd;
100 // 9 - id (!= 0 sequentially)

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

137 little_endian_store_16(acl_buffer, 4, pos - 6 - 2);
138 // 10 - L2CAP signaling parameter length
139 little_endian_store_16(acl_buffer, 10, pos - 12);
140
141 return pos;
142}
143
144uint16_t l2cap_create_signaling_classic(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
98
99 // 0 - Connection handle : PB=pb : BC=00
100 little_endian_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
101 // 6 - L2CAP channel = 1
102 little_endian_store_16(acl_buffer, 6, cid);
103 // 8 - Code
104 acl_buffer[8] = cmd;
105 // 9 - id (!= 0 sequentially)

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

142 little_endian_store_16(acl_buffer, 4, pos - 6 - 2);
143 // 10 - L2CAP signaling parameter length
144 little_endian_store_16(acl_buffer, 10, pos - 12);
145
146 return pos;
147}
148
149uint16_t l2cap_create_signaling_classic(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
145 return l2cap_create_signaling_internal(acl_buffer, handle, 1, cmd, identifier, argptr);
150 return l2cap_create_signaling_internal(acl_buffer, handle, true, 1, cmd, identifier, argptr);
146}
147
148#ifdef ENABLE_BLE
149uint16_t l2cap_create_signaling_le(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
151}
152
153#ifdef ENABLE_BLE
154uint16_t l2cap_create_signaling_le(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
150 return l2cap_create_signaling_internal(acl_buffer, handle, 5, cmd, identifier, argptr);
155 return l2cap_create_signaling_internal(acl_buffer, handle, false, 5, cmd, identifier, argptr);
151}
152#endif
156}
157#endif