The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 1999-2012 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | #ifndef L2CDEFS_H |
| 20 | #define L2CDEFS_H |
| 21 | |
| 22 | /* L2CAP command codes |
| 23 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 24 | #define L2CAP_CMD_REJECT 0x01 |
| 25 | #define L2CAP_CMD_CONN_REQ 0x02 |
| 26 | #define L2CAP_CMD_CONN_RSP 0x03 |
| 27 | #define L2CAP_CMD_CONFIG_REQ 0x04 |
| 28 | #define L2CAP_CMD_CONFIG_RSP 0x05 |
| 29 | #define L2CAP_CMD_DISC_REQ 0x06 |
| 30 | #define L2CAP_CMD_DISC_RSP 0x07 |
| 31 | #define L2CAP_CMD_ECHO_REQ 0x08 |
| 32 | #define L2CAP_CMD_ECHO_RSP 0x09 |
| 33 | #define L2CAP_CMD_INFO_REQ 0x0A |
| 34 | #define L2CAP_CMD_INFO_RSP 0x0B |
| 35 | #define L2CAP_CMD_AMP_CONN_REQ 0x0C |
| 36 | #define L2CAP_CMD_AMP_CONN_RSP 0x0D |
| 37 | #define L2CAP_CMD_AMP_MOVE_REQ 0x0E |
| 38 | #define L2CAP_CMD_AMP_MOVE_RSP 0x0F |
| 39 | #define L2CAP_CMD_AMP_MOVE_CFM 0x10 |
| 40 | #define L2CAP_CMD_AMP_MOVE_CFM_RSP 0x11 |
| 41 | #define L2CAP_CMD_BLE_UPDATE_REQ 0x12 |
| 42 | #define L2CAP_CMD_BLE_UPDATE_RSP 0x13 |
Navin Kochar | 6721232 | 2016-03-09 23:11:53 +0530 | [diff] [blame] | 43 | #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ 0x14 |
| 44 | #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES 0x15 |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 45 | #define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT 0x16 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 46 | |
| 47 | /* Define some packet and header lengths |
| 48 | */ |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 49 | /* Length and CID */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 50 | #define L2CAP_PKT_OVERHEAD 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 51 | /* Cmd code, Id and length */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 52 | #define L2CAP_CMD_OVERHEAD 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 53 | /* Reason (data is optional) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 54 | #define L2CAP_CMD_REJECT_LEN 2 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 55 | /* PSM and source CID */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 56 | #define L2CAP_CONN_REQ_LEN 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 57 | /* Dest CID, source CID, reason, status */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 58 | #define L2CAP_CONN_RSP_LEN 8 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 59 | /* Dest CID, flags (data is optional) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 60 | #define L2CAP_CONFIG_REQ_LEN 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 61 | /* Dest CID, flags, result,data optional*/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 62 | #define L2CAP_CONFIG_RSP_LEN 6 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 63 | /* Dest CID, source CID */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 64 | #define L2CAP_DISC_REQ_LEN 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 65 | /* Dest CID, source CID */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 66 | #define L2CAP_DISC_RSP_LEN 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 67 | /* Data is optional */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 68 | #define L2CAP_ECHO_REQ_LEN 0 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 69 | /* Data is optional */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 70 | #define L2CAP_ECHO_RSP_LEN 0 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 71 | /* Info type */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 72 | #define L2CAP_INFO_REQ_LEN 2 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 73 | /* Info type, result (data is optional) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 74 | #define L2CAP_INFO_RSP_LEN 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 75 | /* Additional connectionless packet overhead */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 76 | #define L2CAP_UCD_OVERHEAD 2 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 77 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 78 | /* PSM, CID, and remote controller ID */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 79 | #define L2CAP_AMP_CONN_REQ_LEN 5 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 80 | /* CID and remote controller ID */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 81 | #define L2CAP_AMP_MOVE_REQ_LEN 3 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 82 | /* CID and result */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 83 | #define L2CAP_AMP_MOVE_RSP_LEN 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 84 | /* CID and result */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 85 | #define L2CAP_AMP_MOVE_CFM_LEN 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 86 | /* CID */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 87 | #define L2CAP_AMP_MOVE_CFM_RSP_LEN 2 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 88 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 89 | /* Min and max interval, latency, tout */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 90 | #define L2CAP_CMD_BLE_UPD_REQ_LEN 8 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 91 | /* Result */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 92 | #define L2CAP_CMD_BLE_UPD_RSP_LEN 2 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 93 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 94 | /* LE_PSM, SCID, MTU, MPS, Init Credit */ |
| 95 | #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ_LEN 10 |
| 96 | /* DCID, MTU, MPS, Init credit, Result */ |
| 97 | #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN 10 |
| 98 | /* CID, Credit */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 99 | #define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT_LEN 4 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 100 | |
| 101 | /* Define the packet boundary flags |
| 102 | */ |
| 103 | #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE) |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 104 | #define L2CAP_PKT_START_FLUSHABLE 2 |
| 105 | #define L2CAP_PKT_START_NON_FLUSHABLE 0 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 106 | #endif |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 107 | #define L2CAP_COMPLETE_AMP_PKT 3 /* complete L2CAP packet on AMP HCI */ |
| 108 | #define L2CAP_PKT_START 2 |
| 109 | #define L2CAP_PKT_CONTINUE 1 |
| 110 | #define L2CAP_MASK_FLAG 0x0FFF |
| 111 | #define L2CAP_PKT_TYPE_SHIFT 12 |
| 112 | #define L2CAP_PKT_TYPE_MASK 3 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 113 | |
| 114 | /* Define the L2CAP connection result codes |
| 115 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 116 | #define L2CAP_CONN_OK 0 |
| 117 | #define L2CAP_CONN_PENDING 1 |
| 118 | #define L2CAP_CONN_NO_PSM 2 |
| 119 | #define L2CAP_CONN_SECURITY_BLOCK 3 |
| 120 | #define L2CAP_CONN_NO_RESOURCES 4 |
| 121 | #define L2CAP_CONN_BAD_CTLR_ID 5 /* AMP related */ |
| 122 | #define L2CAP_CONN_TIMEOUT 0xEEEE |
| 123 | #define L2CAP_CONN_AMP_FAILED 254 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 124 | /* Add a couple of our own for internal use */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 125 | #define L2CAP_CONN_NO_LINK 255 |
| 126 | #define L2CAP_CONN_CANCEL 256 /* L2CAP connection cancelled */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 127 | |
Venkata Jagadeesh | e84afd9 | 2016-03-18 12:04:30 +0530 | [diff] [blame] | 128 | /* Define the LE L2CAP Connection Response Result codes |
| 129 | */ |
| 130 | #define L2CAP_LE_RESULT_CONN_OK 0 |
| 131 | #define L2CAP_LE_RESULT_NO_PSM 2 |
| 132 | #define L2CAP_LE_RESULT_NO_RESOURCES 4 |
| 133 | #define L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION 5 |
| 134 | #define L2CAP_LE_RESULT_INSUFFICIENT_AUTHORIZATION 6 |
| 135 | #define L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP_KEY_SIZE 7 |
| 136 | #define L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP 8 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 137 | /* We don't like peer device response */ |
Venkata Jagadeesh | e84afd9 | 2016-03-18 12:04:30 +0530 | [diff] [blame] | 138 | #define L2CAP_LE_RESULT_INVALID_SOURCE_CID 9 |
| 139 | #define L2CAP_LE_RESULT_SOURCE_CID_ALREADY_ALLOCATED 0x0A |
| 140 | |
| 141 | typedef uint8_t tL2CAP_LE_RESULT_CODE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 142 | |
| 143 | /* Define L2CAP Move Channel Response result codes |
| 144 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 145 | #define L2CAP_MOVE_OK 0 |
| 146 | #define L2CAP_MOVE_PENDING 1 |
| 147 | #define L2CAP_MOVE_CTRL_ID_NOT_SUPPORT 2 |
| 148 | #define L2CAP_MOVE_SAME_CTRLR_ID 3 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 149 | #define L2CAP_MOVE_CONFIG_NOT_SUPPORTED 4 |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 150 | #define L2CAP_MOVE_CHAN_COLLISION 5 |
| 151 | #define L2CAP_MOVE_NOT_ALLOWED 6 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 152 | |
| 153 | /* Define L2CAP Move Channel Confirmation result codes |
| 154 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 155 | #define L2CAP_MOVE_CFM_OK 0 |
| 156 | #define L2CAP_MOVE_CFM_REFUSED 1 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 157 | |
| 158 | /* Define the L2CAP command reject reason codes |
| 159 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 160 | #define L2CAP_CMD_REJ_NOT_UNDERSTOOD 0 |
| 161 | #define L2CAP_CMD_REJ_MTU_EXCEEDED 1 |
| 162 | #define L2CAP_CMD_REJ_INVALID_CID 2 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 163 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 164 | /* L2CAP Predefined CIDs |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 165 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 166 | #define L2CAP_SIGNALLING_CID 1 |
| 167 | #define L2CAP_CONNECTIONLESS_CID 2 |
| 168 | #define L2CAP_AMP_CID 3 |
| 169 | #define L2CAP_ATT_CID 4 |
| 170 | #define L2CAP_BLE_SIGNALLING_CID 5 |
| 171 | #define L2CAP_SMP_CID 6 |
| 172 | #define L2CAP_SMP_BR_CID 7 |
| 173 | #define L2CAP_AMP_TEST_CID 0x003F |
| 174 | #define L2CAP_BASE_APPL_CID 0x0040 |
| 175 | #define L2CAP_BLE_CONN_MAX_CID 0x007F |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 176 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 177 | /* Fixed Channels mask bits */ |
| 178 | |
| 179 | /* Signal channel supported (Mandatory) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 180 | #define L2CAP_FIXED_CHNL_SIG_BIT (1 << L2CAP_SIGNALLING_CID) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 181 | |
| 182 | /* Connectionless reception */ |
| 183 | #define L2CAP_FIXED_CHNL_CNCTLESS_BIT (1 << L2CAP_CONNECTIONLESS_CID) |
| 184 | |
| 185 | /* AMP Manager supported */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 186 | #define L2CAP_FIXED_CHNL_AMP_BIT (1 << L2CAP_AMP_CID) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 187 | |
| 188 | /* Attribute protocol supported */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 189 | #define L2CAP_FIXED_CHNL_ATT_BIT (1 << L2CAP_ATT_CID) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 190 | |
| 191 | /* BLE Signalling supported */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 192 | #define L2CAP_FIXED_CHNL_BLE_SIG_BIT (1 << L2CAP_BLE_SIGNALLING_CID) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 193 | |
| 194 | /* BLE Security Mgr supported */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 195 | #define L2CAP_FIXED_CHNL_SMP_BIT (1 << L2CAP_SMP_CID) |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 196 | |
| 197 | /* Security Mgr over BR supported */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 198 | #define L2CAP_FIXED_CHNL_SMP_BR_BIT (1 << L2CAP_SMP_BR_CID) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 199 | |
| 200 | /* Define the L2CAP configuration result codes |
| 201 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 202 | #define L2CAP_CFG_OK 0 |
| 203 | #define L2CAP_CFG_UNACCEPTABLE_PARAMS 1 |
| 204 | #define L2CAP_CFG_FAILED_NO_REASON 2 |
| 205 | #define L2CAP_CFG_UNKNOWN_OPTIONS 3 |
| 206 | #define L2CAP_CFG_PENDING 4 |
| 207 | #define L2CAP_CFG_FLOW_SPEC_REJECTED 5 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 208 | |
| 209 | /* Define the L2CAP configuration option types |
| 210 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 211 | #define L2CAP_CFG_TYPE_MTU 0x01 |
| 212 | #define L2CAP_CFG_TYPE_FLUSH_TOUT 0x02 |
| 213 | #define L2CAP_CFG_TYPE_QOS 0x03 |
| 214 | #define L2CAP_CFG_TYPE_FCR 0x04 |
| 215 | #define L2CAP_CFG_TYPE_FCS 0x05 |
| 216 | #define L2CAP_CFG_TYPE_EXT_FLOW 0x06 |
| 217 | #define L2CAP_CFG_TYPE_EXT_WIN_SIZE 0x07 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 218 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 219 | #define L2CAP_CFG_MTU_OPTION_LEN 2 /* MTU option length */ |
| 220 | #define L2CAP_CFG_FLUSH_OPTION_LEN 2 /* Flush option len */ |
| 221 | #define L2CAP_CFG_QOS_OPTION_LEN 22 /* QOS option length */ |
| 222 | #define L2CAP_CFG_FCR_OPTION_LEN 9 /* FCR option length */ |
| 223 | #define L2CAP_CFG_FCS_OPTION_LEN 1 /* FCR option length */ |
| 224 | #define L2CAP_CFG_EXT_FLOW_OPTION_LEN 16 /* Extended Flow Spec */ |
| 225 | #define L2CAP_CFG_EXT_WIN_SIZE_LEN 2 /* Ext window size length */ |
| 226 | #define L2CAP_CFG_OPTION_OVERHEAD 2 /* Type and length */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 227 | |
| 228 | /* Configuration Cmd/Rsp Flags mask |
| 229 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 230 | #define L2CAP_CFG_FLAGS_MASK_CONT 0x0001 /* Flags mask: Continuation */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 231 | |
| 232 | /* FCS Check Option values |
| 233 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 234 | #define L2CAP_CFG_FCS_BYPASS 0 /* Bypass the FCS in streaming or ERTM modes */ |
| 235 | #define L2CAP_CFG_FCS_USE \ |
| 236 | 1 /* Use the FCS in streaming or ERTM modes [default] */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 237 | |
| 238 | /* Default values for configuration |
| 239 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 240 | #define L2CAP_NO_AUTOMATIC_FLUSH 0xFFFF |
| 241 | #define L2CAP_NO_RETRANSMISSION 0x0001 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 242 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 243 | #define L2CAP_DEFAULT_MTU (672) |
| 244 | #define L2CAP_DEFAULT_FLUSH_TO L2CAP_NO_AUTOMATIC_FLUSH |
| 245 | #define L2CAP_DEFAULT_SERV_TYPE 1 |
| 246 | #define L2CAP_DEFAULT_TOKEN_RATE 0 |
| 247 | #define L2CAP_DEFAULT_BUCKET_SIZE 0 |
| 248 | #define L2CAP_DEFAULT_PEAK_BANDWIDTH 0 |
| 249 | #define L2CAP_DEFAULT_LATENCY 0xFFFFFFFF |
| 250 | #define L2CAP_DEFAULT_DELAY 0xFFFFFFFF |
| 251 | #define L2CAP_DEFAULT_FCS L2CAP_CFG_FCS_USE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 252 | |
| 253 | /* Define the L2CAP disconnect result codes |
| 254 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 255 | #define L2CAP_DISC_OK 0 |
| 256 | #define L2CAP_DISC_TIMEOUT 0xEEEE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 257 | |
| 258 | /* Define the L2CAP info resp result codes |
| 259 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 260 | #define L2CAP_INFO_RESP_RESULT_SUCCESS 0 |
| 261 | #define L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED 1 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 262 | |
| 263 | /* Define the info-type fields of information request & response |
| 264 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 265 | #define L2CAP_CONNLESS_MTU_INFO_TYPE 0x0001 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 266 | /* Used in Information Req/Response */ |
| 267 | #define L2CAP_EXTENDED_FEATURES_INFO_TYPE 0x0002 |
| 268 | /* Used in AMP */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 269 | #define L2CAP_FIXED_CHANNELS_INFO_TYPE 0x0003 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 270 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 271 | /* Connectionless MTU size */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 272 | #define L2CAP_CONNLESS_MTU_INFO_SIZE 2 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 273 | /* Extended features array size */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 274 | #define L2CAP_EXTENDED_FEATURES_ARRAY_SIZE 4 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 275 | /* Fixed channel array size */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 276 | #define L2CAP_FIXED_CHNL_ARRAY_SIZE 8 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 277 | |
| 278 | /* Extended features mask bits |
| 279 | */ |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 280 | /* Retransmission Mode (Not Supported) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 281 | #define L2CAP_EXTFEA_RTRANS 0x00000001 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 282 | /* Flow Control Mode (Not Supported) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 283 | #define L2CAP_EXTFEA_FC 0x00000002 |
| 284 | #define L2CAP_EXTFEA_QOS 0x00000004 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 285 | /* Enhanced retransmission mode */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 286 | #define L2CAP_EXTFEA_ENH_RETRANS 0x00000008 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 287 | /* Streaming Mode */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 288 | #define L2CAP_EXTFEA_STREAM_MODE 0x00000010 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 289 | /* Optional FCS (if set No FCS desired) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 290 | #define L2CAP_EXTFEA_NO_CRC 0x00000020 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 291 | /* Extended flow spec */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 292 | #define L2CAP_EXTFEA_EXT_FLOW_SPEC 0x00000040 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 293 | /* Fixed channels */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 294 | #define L2CAP_EXTFEA_FIXED_CHNLS 0x00000080 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 295 | /* Extended Window Size */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 296 | #define L2CAP_EXTFEA_EXT_WINDOW 0x00000100 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 297 | /* Unicast Connectionless Data Reception */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 298 | #define L2CAP_EXTFEA_UCD_RECEPTION 0x00000200 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 299 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 300 | /* Mask for locally supported features used in Information Response |
| 301 | * (default to none) */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 302 | #ifndef L2CAP_EXTFEA_SUPPORTED_MASK |
| 303 | #define L2CAP_EXTFEA_SUPPORTED_MASK 0 |
| 304 | #endif |
| 305 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 306 | /* Mask for LE supported features used in Information Response |
| 307 | * (default to none) */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 308 | #ifndef L2CAP_BLE_EXTFEA_MASK |
| 309 | #define L2CAP_BLE_EXTFEA_MASK 0 |
| 310 | #endif |
| 311 | |
Pavlin Radoslavov | 1d5b859 | 2015-09-23 10:08:20 -0700 | [diff] [blame] | 312 | /* Define a value that tells L2CAP to use the default HCI ACL buffer size */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 313 | #define L2CAP_INVALID_ERM_BUF_SIZE 0 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 314 | /* Define a value that tells L2CAP to use the default MPS */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 315 | #define L2CAP_DEFAULT_ERM_MPS 0x0000 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 316 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 317 | #define L2CAP_FCR_OVERHEAD 2 /* Control word */ |
| 318 | #define L2CAP_FCS_LEN 2 /* FCS takes 2 bytes */ |
| 319 | #define L2CAP_SDU_LEN_OVERHEAD 2 /* SDU length field is 2 bytes */ |
| 320 | #define L2CAP_SDU_LEN_OFFSET 2 /* SDU length offset is 2 bytes */ |
| 321 | #define L2CAP_EXT_CONTROL_OVERHEAD 4 /* Extended Control Field */ |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 322 | /* length(2), channel(2), control(4), SDU length(2) FCS(2) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 323 | #define L2CAP_MAX_HEADER_FCS \ |
| 324 | (L2CAP_PKT_OVERHEAD + L2CAP_EXT_CONTROL_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + \ |
| 325 | L2CAP_FCS_LEN) |
Srinu Jella | f19ca75 | 2016-01-22 15:34:16 +0530 | [diff] [blame] | 326 | |
Jakub Pawlowski | 622bd22 | 2018-01-30 15:40:03 -0800 | [diff] [blame] | 327 | /* TODO: This value can probably be optimized per transport, and per L2CAP |
| 328 | * socket type, but this should not bring any big performance improvements. For |
| 329 | * LE CoC, it should be biggest multiple of "PDU length" smaller than 0xffff (so |
| 330 | * depend on controller buffer size), for Classic, making it multiple of PDU |
| 331 | * length and also of the 3DH5 air including the l2cap headers in each packet. |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 332 | */ |
Jakub Pawlowski | 622bd22 | 2018-01-30 15:40:03 -0800 | [diff] [blame] | 333 | #define L2CAP_SDU_LENGTH_MAX (8080 + 26 - (L2CAP_MIN_OFFSET + 6)) |
| 334 | constexpr uint16_t L2CAP_SDU_LENGTH_LE_MAX = 0xffff; |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 335 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 336 | /* Part of L2CAP_MIN_OFFSET that is not part of L2CAP |
| 337 | */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 338 | #define L2CAP_OFFSET_WO_L2HDR \ |
| 339 | (L2CAP_MIN_OFFSET - (L2CAP_PKT_OVERHEAD + L2CAP_FCR_OVERHEAD)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 340 | |
| 341 | /* SAR bits in the control word |
| 342 | */ |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 343 | /* Control word to begin with for unsegmented PDU*/ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 344 | #define L2CAP_FCR_UNSEG_SDU 0x0000 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 345 | /* ...for Starting PDU of a semented SDU */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 346 | #define L2CAP_FCR_START_SDU 0x4000 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 347 | /* ...for ending PDU of a segmented SDU */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 348 | #define L2CAP_FCR_END_SDU 0x8000 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 349 | /* ...for continuation PDU of a segmented SDU */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 350 | #define L2CAP_FCR_CONT_SDU 0xc000 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 351 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 352 | /* Supervisory frame types */ |
| 353 | /* Supervisory frame - RR */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 354 | #define L2CAP_FCR_SUP_RR 0x0000 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 355 | /* Supervisory frame - REJ */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 356 | #define L2CAP_FCR_SUP_REJ 0x0001 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 357 | /* Supervisory frame - RNR */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 358 | #define L2CAP_FCR_SUP_RNR 0x0002 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 359 | /* Supervisory frame - SREJ */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 360 | #define L2CAP_FCR_SUP_SREJ 0x0003 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 361 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 362 | /* Mask to get the SAR bits from control word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 363 | #define L2CAP_FCR_SAR_BITS 0xC000 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 364 | /* Bits to shift right to get the SAR bits from ctrl-word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 365 | #define L2CAP_FCR_SAR_BITS_SHIFT 14 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 367 | /* Mask to check if a PDU is S-frame */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 368 | #define L2CAP_FCR_S_FRAME_BIT 0x0001 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 369 | /* Mask to get the req-seq from control word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 370 | #define L2CAP_FCR_REQ_SEQ_BITS 0x3F00 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 371 | /* Bits to shift right to get the req-seq from ctrl-word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 372 | #define L2CAP_FCR_REQ_SEQ_BITS_SHIFT 8 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 373 | /* Mask on get the tx-seq from control word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 374 | #define L2CAP_FCR_TX_SEQ_BITS 0x007E |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 375 | /* Bits to shift right to get the tx-seq from ctrl-word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 376 | #define L2CAP_FCR_TX_SEQ_BITS_SHIFT 1 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 377 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 378 | /* F-bit in the control word (Sup and I frames) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 379 | #define L2CAP_FCR_F_BIT 0x0080 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 380 | /* P-bit in the control word (Sup frames only) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 381 | #define L2CAP_FCR_P_BIT 0x0010 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 382 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 383 | #define L2CAP_FCR_F_BIT_SHIFT 7 |
| 384 | #define L2CAP_FCR_P_BIT_SHIFT 4 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 385 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 386 | /* Mask to get the segmentation bits from ctrl-word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 387 | #define L2CAP_FCR_SEG_BITS 0xC000 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 388 | /* Bits to shift right to get the S-bits from ctrl-word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 389 | #define L2CAP_FCR_SUP_SHIFT 2 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 390 | /* Mask to get the supervisory bits from ctrl-word */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 391 | #define L2CAP_FCR_SUP_BITS 0x000C |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 392 | |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 393 | /* Initial state of the CRC register */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 394 | #define L2CAP_FCR_INIT_CRC 0 |
Myles Watson | 9ca0709 | 2016-11-28 16:41:53 -0800 | [diff] [blame] | 395 | /* Mask for sequence numbers (range 0 - 63) */ |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 396 | #define L2CAP_FCR_SEQ_MODULO 0x3F |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 397 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 398 | #endif |