1 /* 2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 **************************************************************************************** 18 * 19 * @file sonata_gap.h 20 * 21 * @brief Header file - GAP. 22 * 23 **************************************************************************************** 24 */ 25 #ifndef SONATA_GAP_H_ 26 #define SONATA_GAP_H_ 27 /** 28 **************************************************************************************** 29 * @addtogroup HOST 30 * @ingroup ROOT 31 * @brief Bluetooth Low Energy Host 32 * 33 * The HOST layer of the stack contains the higher layer protocols (@ref ATT "ATT", 34 * @ref SMP "SMP") and transport module (@ref L2C "L2C"). It also includes the Generic 35 * Access Profile (@ref GAP "GAP"), used for scanning/connection operations. 36 **************************************************************************************** 37 */ 38 /** 39 **************************************************************************************** 40 * @addtogroup GAP Generic Access Profile 41 * @ingroup HOST 42 * @brief Generic Access Profile. 43 * 44 * The GAP module is responsible for providing an API to the application in order to 45 * configure the device in the desired mode (discoverable, connectable, etc.) and perform 46 * required actions (scanning, connection, pairing, etc.). To achieve this, the GAP 47 * interfaces with both the @ref SMP "SMP", @ref L2C "L2C" and the @ref CONTROLLER "CONTROLLER" 48 * 49 * @{ 50 **************************************************************************************** 51 */ 52 53 #include <stdint.h> 54 #include "compiler.h" 55 56 /* 57 * DEFINES 58 **************************************************************************************** 59 */ 60 61 // BD address length 62 #define SONATA_GAP_BD_ADDR_LEN (6) 63 // LE Channel map length 64 #define SONATA_GAP_LE_CHNL_MAP_LEN (0x05) 65 // LE Feature Flags Length 66 #define SONATA_GAP_LE_FEATS_LEN (0x08) 67 // ADV Data and Scan Response length 68 #define SONATA_GAP_ADV_DATA_LEN (0x1F) 69 #define SONATA_GAP_SCAN_RSP_DATA_LEN (0x1F) 70 // Random number length 71 #define SONATA_GAP_RAND_NB_LEN (0x08) 72 // Key length 73 #define SONATA_GAP_KEY_LEN (16) 74 // P256 Key Len 75 #define SONATA_GAP_P256_KEY_LEN (0x20) 76 77 /***** AD Type Flag - Bit set *******/ 78 // Limited discovery flag - AD Flag 79 #define SONATA_GAP_LE_LIM_DISCOVERABLE_FLG 0x01 80 // General discovery flag - AD Flag 81 #define SONATA_GAP_LE_GEN_DISCOVERABLE_FLG 0x02 82 // Legacy BT not supported - AD Flag 83 #define SONATA_GAP_BR_EDR_NOT_SUPPORTED 0x04 84 // Dual mode for controller supported (BR/EDR/LE) - AD Flag 85 #define SONATA_GAP_SIMUL_BR_EDR_LE_CONTROLLER 0x08 86 // Dual mode for host supported (BR/EDR/LE) - AD Flag 87 #define SONATA_GAP_SIMUL_BR_EDR_LE_HOST 0x10 88 89 /*********** GAP Miscellaneous Defines *************/ 90 // Invalid activity index 91 #define SONATA_GAP_INVALID_ACTV_IDX 0xFF 92 // Invalid connection index 93 #define SONATA_GAP_INVALID_CONIDX 0xFF 94 95 // Invalid connection handle 96 #define SONATA_GAP_INVALID_CONHDL 0xFFFF 97 98 // Connection interval min (N*1.250ms) 99 #define SONATA_GAP_CNX_INTERVAL_MIN 6 // (0x06) 100 // Connection interval Max (N*1.250ms) 101 #define SONATA_GAP_CNX_INTERVAL_MAX 3200 // (0xC80) 102 // Connection latency min (N*cnx evt) 103 #define SONATA_GAP_CNX_LATENCY_MIN 0 // (0x00) 104 // Connection latency Max (N*cnx evt 105 #define SONATA_GAP_CNX_LATENCY_MAX 499 // (0x1F3) 106 // Supervision TO min (N*10ms) 107 #define SONATA_GAP_CNX_SUP_TO_MIN 10 // (0x0A) 108 // Supervision TO Max (N*10ms) 109 #define SONATA_GAP_CNX_SUP_TO_MAX 3200 // (0xC80) 110 111 // Length of resolvable random address prand part 112 #define SONATA_GAP_ADDR_PRAND_LEN (3) 113 // Length of resolvable random address hash part 114 #define SONATA_GAP_ADDR_HASH_LEN (3) 115 116 // Number of bytes needed for a bit field indicated presence of a given Advertising Flag value 117 // in the Advertising or the Scan Response data 118 // Advertising Flags is a 8-bit value, hence 256 value are possible 119 // -> 256 / 8 bytes = 32 bytes are needed 120 #define SONATA_GAP_AD_TYPE_BITFIELD_BYTES (32) 121 122 /* 123 * DEFINES - Optional for BLE application usage 124 **************************************************************************************** 125 */ 126 127 // Central idle timer 128 // TGAP(conn_pause_central) 129 // recommended value: 1 s: (100 for ke timer) 130 #define SONATA_GAP_TMR_CONN_PAUSE_CT 0x0064 131 132 // Minimum time upon connection establishment before the peripheral 133 // starts a connection update procedure: TGAP(conn_pause_peripheral) 134 // recommended value: 5 s: (500 for ke timer) 135 #define SONATA_GAP_TMR_CONN_PAUSE_PH 0x01F4 136 137 // Minimum time to perform scanning when user initiated 138 // TGAP(scan_fast_period) 139 // recommended value: 30.72 s: (3072 for ke timer) 140 #define SONATA_GAP_TMR_SCAN_FAST_PERIOD 0x0C00 141 142 // Minimum time to perform advertising when user initiated 143 // TGAP(adv_fast_period) 144 // recommended value: 30 s: (3000 for ke timer) 145 #define SONATA_GAP_TMR_ADV_FAST_PERIOD 0x0BB8 146 147 // Scan interval used during Link Layer Scanning State when 148 // performing the Limited Discovery procedure 149 // TGAP(lim_disc_scan_int) 150 // recommended value: 11.25ms; (18 decimal) 151 #define SONATA_GAP_LIM_DISC_SCAN_INT 0x0012 152 153 // Scan interval in any discovery or connection establishment 154 // procedure when user initiated: TGAP(scan_fast_interval) 155 // recommended value: 30 to 60 ms; N * 0.625 156 #define SONATA_GAP_SCAN_FAST_INTV 0x0030 157 158 // Scan window in any discovery or connection establishment 159 // procedure when user initiated: TGAP(scan_fast_window) 160 // recommended value: 30 ms; N * 0.625 161 #define SONATA_GAP_SCAN_FAST_WIND 0x0030 162 163 // Scan interval in any discovery or connection establishment 164 // procedure when background scanning: TGAP(scan_slow_interval1) 165 // recommended value: 1.28 s : 0x00CD (205); N * 0.625 166 #define SONATA_GAP_SCAN_SLOW_INTV1 0x00CD 167 168 // Scan interval in any discovery or connection establishment 169 // procedure when background scanning: TGAP(scan_slow_interval2) 170 // recommended value: 2.56 s : 0x019A (410); N * 0.625 171 #define SONATA_GAP_SCAN_SLOW_INTV2 0x019A 172 173 // Scan window in any discovery or connection establishment 174 // procedure when background scanning: TGAP(scan_slow_window1) 175 // recommended value: 11.25 ms : 0x0012 (18); N * 0.625 176 #define SONATA_GAP_SCAN_SLOW_WIND1 0x0012 177 178 // Scan window in any discovery or connection establishment 179 // procedure when background scanning: TGAP(scan_slow_window2) 180 // recommended value: 22.5 ms : 0x0024 (36); N * 0.625 181 #define SONATA_GAP_SCAN_SLOW_WIND2 0x0024 182 183 // Minimum to maximum advertisement interval in any discoverable 184 // or connectable mode when user initiated: TGAP(adv_fast_interval1) 185 // recommended value: 30 to 60 ms; N * 0.625 186 #define SONATA_GAP_ADV_FAST_INTV1 0x0030 187 188 // Minimum to maximum advertisement interval in any discoverable 189 // or connectable mode when user initiated: TGAP(adv_fast_interval2) 190 // recommended value: 100 to 150 ms; N * 0.625 191 #define SONATA_GAP_ADV_FAST_INTV2 0x0064 192 193 // Minimum to maximum advertisement interval in any discoverable or 194 // connectable mode when background advertising: TGAP(adv_slow_interval) 195 // recommended value: 1 to 1.2 s : 0x00B0 (176); N * 0.625 196 #define SONATA_GAP_ADV_SLOW_INTV 0x00B0 197 198 // Minimum to maximum connection interval upon any connection 199 // establishment: TGAP(initial_conn_interval) 200 // recommended value: 30 to 50 ms ; N * 1.25 ms 201 #define SONATA_GAP_INIT_CONN_MIN_INTV 0x0018 202 #define SONATA_GAP_INIT_CONN_MAX_INTV 0x0028 203 204 // RW Defines 205 #define SONATA_GAP_INQ_SCAN_INTV 0x0012 206 #define SONATA_GAP_INQ_SCAN_WIND 0x0012 207 208 // Connection supervision timeout 209 // recommended value: 20s 210 #define SONATA_GAP_CONN_SUPERV_TIMEOUT 0x07D0 211 212 // Minimum connection event 213 // default value: 0x0000 214 #define SONATA_GAP_CONN_MIN_CE 0x0000 215 216 // Maximum connection event 217 // default value: 0xFFFF 218 #define SONATA_GAP_CONN_MAX_CE 0xFFFF 219 220 // Connection latency 221 // default value: 0x0000 222 #define SONATA_GAP_CONN_LATENCY 0x0000 223 224 // GAP Device name Characteristic 225 // Default device name 226 #define SONATA_GAP_DEV_NAME_DEFAULT "ASR-BLE" 227 228 // GAP Appearance or Icon Characteristic - 2 octets 229 // Current appearance value is 0x0000 (unknown appearance) 230 // Description: 231 // http:// developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml 232 #define SONATA_GAP_APPEARANCE 0x0000 233 234 /// GAP Peripheral Preferred Connection Parameter - 8 octets 235 #define SONATA_GAP_PPCP_CONN_INTV_MAX 0x0064 236 #define SONATA_GAP_PPCP_CONN_INTV_MIN 0x00C8 237 #define SONATA_GAP_PPCP_SLAVE_LATENCY 0x0000 238 #define SONATA_GAP_PPCP_STO_MULT 0x07D0 239 240 /* 241 * Macros 242 **************************************************************************************** 243 */ 244 245 #define SONATA_GAP_AD_TYPE_SET_BIT(bitfield, adv_flag) \ 246 bitfield[(adv_flag) / 8] |= CO_BIT((adv_flag) % 8) 247 248 #define SONATA_GAP_AD_TYPE_CHECK_BIT(bitfield, adv_flag) \ 249 (bitfield[(adv_flag) / 8] & CO_BIT((adv_flag) % 8)) 250 251 /* 252 * Enumerations 253 **************************************************************************************** 254 */ 255 // GAP Advertising Flags 256 enum sonata_gap_ad_type { 257 // Flag 258 SONATA_GAP_AD_TYPE_FLAGS = 0x01, // !< SONATA_GAP_AD_TYPE_FLAGS 259 // Use of more than 16 bits UUID 260 SONATA_GAP_AD_TYPE_MORE_16_BIT_UUID = 0x02, // !< SONATA_GAP_AD_TYPE_MORE_16_BIT_UUID 261 // Complete list of 16 bit UUID 262 SONATA_GAP_AD_TYPE_COMPLETE_LIST_16_BIT_UUID = 0x03, // !< SONATA_GAP_AD_TYPE_COMPLETE_LIST_16_BIT_UUID 263 // Use of more than 32 bit UUD 264 SONATA_GAP_AD_TYPE_MORE_32_BIT_UUID = 0x04, // !< SONATA_GAP_AD_TYPE_MORE_32_BIT_UUID 265 // Complete list of 32 bit UUID 266 SONATA_GAP_AD_TYPE_COMPLETE_LIST_32_BIT_UUID = 0x05, // !< SONATA_GAP_AD_TYPE_COMPLETE_LIST_32_BIT_UUID 267 // Use of more than 128 bit UUID 268 SONATA_GAP_AD_TYPE_MORE_128_BIT_UUID = 0x06, // !< SONATA_GAP_AD_TYPE_MORE_128_BIT_UUID 269 // Complete list of 128 bit UUID 270 SONATA_GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID = 0x07, // !< SONATA_GAP_AD_TYPE_COMPLETE_LIST_128_BIT_UUID 271 // Shortened device name 272 SONATA_GAP_AD_TYPE_SHORTENED_NAME = 0x08, // !< SONATA_GAP_AD_TYPE_SHORTENED_NAME 273 // Complete device name 274 SONATA_GAP_AD_TYPE_COMPLETE_NAME = 0x09, // !< SONATA_GAP_AD_TYPE_COMPLETE_NAME 275 // Transmit power 276 SONATA_GAP_AD_TYPE_TRANSMIT_POWER = 0x0A, // !< SONATA_GAP_AD_TYPE_TRANSMIT_POWER 277 // Class of device 278 SONATA_GAP_AD_TYPE_CLASS_OF_DEVICE = 0x0D, // !< SONATA_GAP_AD_TYPE_CLASS_OF_DEVICE 279 // Simple Pairing Hash C 280 SONATA_GAP_AD_TYPE_SP_HASH_C = 0x0E, // !< SONATA_GAP_AD_TYPE_SP_HASH_C 281 // Simple Pairing Randomizer 282 SONATA_GAP_AD_TYPE_SP_RANDOMIZER_R = 0x0F, // !< SONATA_GAP_AD_TYPE_SP_RANDOMIZER_R 283 // Temporary key value 284 SONATA_GAP_AD_TYPE_TK_VALUE = 0x10, // !< SONATA_GAP_AD_TYPE_TK_VALUE 285 // Out of Band Flag 286 SONATA_GAP_AD_TYPE_OOB_FLAGS = 0x11, // !< SONATA_GAP_AD_TYPE_OOB_FLAGS 287 // Slave connection interval range 288 SONATA_GAP_AD_TYPE_SLAVE_CONN_INT_RANGE = 0x12, // !< SONATA_GAP_AD_TYPE_SLAVE_CONN_INT_RANGE 289 // Require 16 bit service UUID 290 SONATA_GAP_AD_TYPE_RQRD_16_BIT_SVC_UUID = 0x14, // !< SONATA_GAP_AD_TYPE_RQRD_16_BIT_SVC_UUID 291 // Require 32 bit service UUID 292 SONATA_GAP_AD_TYPE_RQRD_32_BIT_SVC_UUID = 0x1F, // !< SONATA_GAP_AD_TYPE_RQRD_32_BIT_SVC_UUID 293 // Require 128 bit service UUID 294 SONATA_GAP_AD_TYPE_RQRD_128_BIT_SVC_UUID = 0x15, // !< SONATA_GAP_AD_TYPE_RQRD_128_BIT_SVC_UUID 295 // Service data 16-bit UUID 296 SONATA_GAP_AD_TYPE_SERVICE_16_BIT_DATA = 0x16, // !< SONATA_GAP_AD_TYPE_SERVICE_16_BIT_DATA 297 // Service data 32-bit UUID 298 SONATA_GAP_AD_TYPE_SERVICE_32_BIT_DATA = 0x20, // !< SONATA_GAP_AD_TYPE_SERVICE_32_BIT_DATA 299 // Service data 128-bit UUID 300 SONATA_GAP_AD_TYPE_SERVICE_128_BIT_DATA = 0x21, // !< SONATA_GAP_AD_TYPE_SERVICE_128_BIT_DATA 301 // Public Target Address 302 SONATA_GAP_AD_TYPE_PUB_TGT_ADDR = 0x17, // !< SONATA_GAP_AD_TYPE_PUB_TGT_ADDR 303 // Random Target Address 304 SONATA_GAP_AD_TYPE_RAND_TGT_ADDR = 0x18, // !< SONATA_GAP_AD_TYPE_RAND_TGT_ADDR 305 // Appearance 306 SONATA_GAP_AD_TYPE_APPEARANCE = 0x19, // !< SONATA_GAP_AD_TYPE_APPEARANCE 307 // Advertising Interval 308 SONATA_GAP_AD_TYPE_ADV_INTV = 0x1A, // !< SONATA_GAP_AD_TYPE_ADV_INTV 309 // LE Bluetooth Device Address 310 SONATA_GAP_AD_TYPE_LE_BT_ADDR = 0x1B, // !< SONATA_GAP_AD_TYPE_LE_BT_ADDR 311 // LE Role 312 SONATA_GAP_AD_TYPE_LE_ROLE = 0x1C, // !< SONATA_GAP_AD_TYPE_LE_ROLE 313 // Simple Pairing Hash C-256 314 SONATA_GAP_AD_TYPE_SPAIR_HASH = 0x1D, // !< SONATA_GAP_AD_TYPE_SPAIR_HASH 315 // Simple Pairing Randomizer R-256 316 SONATA_GAP_AD_TYPE_SPAIR_RAND = 0x1E, // !< SONATA_GAP_AD_TYPE_SPAIR_RAND 317 // 3D Information Data 318 SONATA_GAP_AD_TYPE_3D_INFO = 0x3D, // !< SONATA_GAP_AD_TYPE_3D_INFO 319 320 // Manufacturer specific data 321 SONATA_GAP_AD_TYPE_MANU_SPECIFIC_DATA = 0xFF, // !< SONATA_GAP_AD_TYPE_MANU_SPECIFIC_DATA 322 }; 323 324 // Boolean value set 325 enum { 326 // Disable 327 SONATA_GAP_DISABLE = 0x00, 328 // Enable 329 SONATA_GAP_ENABLE 330 }; 331 332 // GAP Attribute database handles 333 // Generic Access Profile Service 334 enum { 335 SONATA_GAP_IDX_PRIM_SVC, 336 SONATA_GAP_IDX_CHAR_DEVNAME, 337 SONATA_GAP_IDX_DEVNAME, 338 SONATA_GAP_IDX_CHAR_ICON, 339 SONATA_GAP_IDX_ICON, 340 SONATA_GAP_IDX_CHAR_SLAVE_PREF_PARAM, 341 SONATA_GAP_IDX_SLAVE_PREF_PARAM, 342 SONATA_GAP_IDX_CHAR_CNT_ADDR_RESOL, 343 SONATA_GAP_IDX_CNT_ADDR_RESOL, 344 SONATA_GAP_IDX_CHAR_RSLV_PRIV_ADDR_ONLY, 345 SONATA_GAP_IDX_RSLV_PRIV_ADDR_ONLY, 346 SONATA_GAP_IDX_NUMBER 347 }; 348 349 // IO Capability Values 350 enum sonata_gap_io_cap { 351 // Display Only 352 SONATA_GAP_IO_CAP_DISPLAY_ONLY = 0x00, 353 // Display Yes No 354 SONATA_GAP_IO_CAP_DISPLAY_YES_NO, 355 // Keyboard Only 356 SONATA_GAP_IO_CAP_KB_ONLY, 357 // No Input No Output 358 SONATA_GAP_IO_CAP_NO_INPUT_NO_OUTPUT, 359 // Keyboard Display 360 SONATA_GAP_IO_CAP_KB_DISPLAY, 361 SONATA_GAP_IO_CAP_LAST 362 }; 363 364 // TK Type 365 enum sonata_gap_tk_type { 366 // TK get from out of band method 367 SONATA_GAP_TK_OOB = 0x00, 368 // TK generated and shall be displayed by local device 369 SONATA_GAP_TK_DISPLAY, 370 // TK shall be entered by user using device keyboard 371 SONATA_GAP_TK_KEY_ENTRY 372 }; 373 374 // OOB Data Present Flag Values 375 enum sonata_gap_oob_auth { 376 // OOB Data not present 377 SONATA_GAP_OOB_AUTH_DATA_NOT_PRESENT = 0x00, 378 // OOB data present 379 SONATA_GAP_OOB_AUTH_DATA_PRESENT, 380 SONATA_GAP_OOB_AUTH_DATA_LAST 381 }; 382 383 // Authentication mask 384 enum sonata_gap_auth_mask { 385 // No Flag set 386 SONATA_GAP_AUTH_NONE = 0, 387 // Bond authentication 388 SONATA_GAP_AUTH_BOND = (1 << 0), 389 // Man In the middle protection 390 SONATA_GAP_AUTH_MITM = (1 << 2), 391 // Secure Connection 392 SONATA_GAP_AUTH_SEC_CON = (1 << 3), 393 // Key Notification 394 SONATA_GAP_AUTH_KEY_NOTIF = (1 << 4) 395 }; 396 397 // Security Link Level 398 enum sonata_gap_lk_sec_lvl { 399 // No authentication 400 SONATA_GAP_LK_NO_AUTH = 0, 401 // Unauthenticated link 402 SONATA_GAP_LK_UNAUTH, 403 // Authenticated link 404 SONATA_GAP_LK_AUTH, 405 // Secure Connection link 406 SONATA_GAP_LK_SEC_CON, 407 }; 408 409 // Authentication Requirements 410 enum sonata_gap_auth { 411 // No MITM No Bonding 412 SONATA_GAP_AUTH_REQ_NO_MITM_NO_BOND = (SONATA_GAP_AUTH_NONE), 413 // No MITM Bonding 414 SONATA_GAP_AUTH_REQ_NO_MITM_BOND = (SONATA_GAP_AUTH_BOND), 415 // MITM No Bonding 416 SONATA_GAP_AUTH_REQ_MITM_NO_BOND = (SONATA_GAP_AUTH_MITM), 417 // MITM and Bonding 418 SONATA_GAP_AUTH_REQ_MITM_BOND = (SONATA_GAP_AUTH_MITM | SONATA_GAP_AUTH_BOND), 419 // SEC_CON and No Bonding 420 SONATA_GAP_AUTH_REQ_SEC_CON_NO_BOND = (SONATA_GAP_AUTH_SEC_CON | SONATA_GAP_AUTH_MITM), 421 // SEC_CON and Bonding 422 SONATA_GAP_AUTH_REQ_SEC_CON_BOND = (SONATA_GAP_AUTH_SEC_CON | SONATA_GAP_AUTH_MITM | SONATA_GAP_AUTH_BOND), 423 424 SONATA_GAP_AUTH_REQ_LAST, 425 426 // Mask of authentication features without reserved flag 427 SONATA_GAP_AUTH_REQ_MASK = 0x1F, 428 }; 429 430 // Key Distribution Flags 431 enum sonata_gap_kdist { 432 // No Keys to distribute 433 SONATA_GAP_KDIST_NONE = 0x00, 434 // Encryption key in distribution 435 SONATA_GAP_KDIST_ENCKEY = (1 << 0), 436 // IRK (ID key)in distribution 437 SONATA_GAP_KDIST_IDKEY = (1 << 1), 438 // CSRK(Signature key) in distribution 439 SONATA_GAP_KDIST_SIGNKEY = (1 << 2), 440 // LTK in distribution 441 SONATA_GAP_KDIST_LINKKEY = (1 << 3), 442 443 SONATA_GAP_KDIST_LAST = (1 << 4) 444 }; 445 446 // Security Defines 447 enum sonata_gap_sec_req { 448 // No security (no authentication and encryption) 449 SONATA_GAP_NO_SEC = 0x00, 450 // Unauthenticated pairing with encryption 451 SONATA_GAP_SEC1_NOAUTH_PAIR_ENC, 452 // Authenticated pairing with encryption 453 SONATA_GAP_SEC1_AUTH_PAIR_ENC, 454 // Unauthenticated pairing with data signing 455 SONATA_GAP_SEC2_NOAUTH_DATA_SGN, 456 // Authentication pairing with data signing 457 SONATA_GAP_SEC2_AUTH_DATA_SGN, 458 // Secure Connection pairing with encryption 459 SONATA_GAP_SEC1_SEC_CON_PAIR_ENC, 460 }; 461 462 // Bit field use to select the preferred TX or RX LE PHY. 0 means no preferences 463 enum sonata_gap_phy { 464 // No preferred PHY 465 SONATA_GAP_PHY_ANY = 0x00, 466 // LE 1M PHY preferred for an active link 467 SONATA_GAP_PHY_LE_1MBPS = (1 << 0), 468 // LE 2M PHY preferred for an active link 469 SONATA_GAP_PHY_LE_2MBPS = (1 << 1), 470 // LE Coded PHY preferred for an active link 471 SONATA_GAP_PHY_LE_CODED = (1 << 2), 472 }; 473 474 // Enumeration of TX/RX PHY values 475 enum sonata_gap_phy_val { 476 // LE 1M PHY (TX or RX) 477 SONATA_GAP_PHY_1MBPS = 1, 478 // LE 2M PHY (TX or RX) 479 SONATA_GAP_PHY_2MBPS = 2, 480 // LE Coded PHY (RX Only) 481 SONATA_GAP_PHY_CODED = 3, 482 // LE Coded PHY with S=8 data coding (TX Only) 483 SONATA_GAP_PHY_125KBPS = 3, 484 // LE Coded PHY with S=2 data coding (TX Only) 485 SONATA_GAP_PHY_500KBPS = 4, 486 }; 487 488 // Modulation index 489 enum sonata_gap_modulation_idx { // Assume transmitter will have a standard modulation index 490 SONATA_GAP_MODULATION_STANDARD, 491 // Assume transmitter will have a stable modulation index 492 SONATA_GAP_MODULATION_STABLE, 493 }; 494 495 // Packet Payload type for test mode 496 enum sonata_gap_pkt_pld_type { // PRBS9 sequence "11111111100000111101..." (in transmission order) 497 SONATA_GAP_PKT_PLD_PRBS9, 498 // Repeated "11110000" (in transmission order) 499 SONATA_GAP_PKT_PLD_REPEATED_11110000, 500 // Repeated "10101010" (in transmission order) 501 SONATA_GAP_PKT_PLD_REPEATED_10101010, 502 // PRBS15 sequence 503 SONATA_GAP_PKT_PLD_PRBS15, 504 // Repeated "11111111" (in transmission order) sequence 505 SONATA_GAP_PKT_PLD_REPEATED_11111111, 506 // Repeated "00000000" (in transmission order) sequence 507 SONATA_GAP_PKT_PLD_REPEATED_00000000, 508 // Repeated "00001111" (in transmission order) sequence 509 SONATA_GAP_PKT_PLD_REPEATED_00001111, 510 // Repeated "01010101" (in transmission order) sequence 511 SONATA_GAP_PKT_PLD_REPEATED_01010101, 512 }; 513 514 /*************** GAP Structures ********************/ 515 516 // Device name 517 /* @TRACE */ 518 struct sonata_gap_dev_name { 519 // name length 520 uint16_t length; 521 // name value 522 uint8_t value[__ARRAY_EMPTY]; 523 }; 524 525 // Slave preferred connection parameters 526 /* @TRACE */ 527 struct sonata_gap_slv_pref { 528 // Connection interval minimum 529 uint16_t con_intv_min; 530 // Connection interval maximum 531 uint16_t con_intv_max; 532 // Slave latency 533 uint16_t slave_latency; 534 // Connection supervision timeout multiplier 535 uint16_t conn_timeout; 536 }; 537 538 /// BD Address structure 539 /* @TRACE */ 540 typedef struct { 541 /// 6-byte array address value 542 uint8_t addr[SONATA_GAP_BD_ADDR_LEN]; 543 } sonata_bd_addr_t; 544 545 /// Channel map structure 546 /* @TRACE */ 547 typedef struct { 548 /// 5-byte channel map array 549 uint8_t map[SONATA_GAP_LE_CHNL_MAP_LEN]; 550 } sonata_le_chnl_map_t; 551 552 /// Random number structure 553 /* @TRACE */ 554 typedef struct { 555 /// 8-byte array for random number 556 uint8_t nb[SONATA_GAP_RAND_NB_LEN]; 557 } sonata_rand_nb_t; 558 559 // Address information about a device address 560 /* @TRACE */ 561 struct sonata_gap_bdaddr { 562 // BD Address of device 563 sonata_bd_addr_t addr; 564 // Address type of the device 0=public/1=private random 565 uint8_t addr_type; 566 }; 567 568 // Resolving list device information 569 /* @TRACE */ 570 struct sonata_gap_ral_dev_info { 571 // Device identity 572 struct sonata_gap_bdaddr addr; 573 // Privacy Mode 574 uint8_t priv_mode; 575 // Peer IRK 576 uint8_t peer_irk[SONATA_GAP_KEY_LEN]; 577 // Local IRK 578 uint8_t local_irk[SONATA_GAP_KEY_LEN]; 579 }; 580 581 // Generic Security key structure 582 /* @TRACE */ 583 struct sonata_gap_sec_key { 584 // Key value MSB -> LSB 585 uint8_t key[SONATA_GAP_KEY_LEN]; 586 }; 587 588 // I/Q sample 589 /* @TRACE */ 590 struct sonata_gap_iq_sample { 591 // I sample 592 int8_t i; 593 // Q sample 594 int8_t q; 595 }; 596 597 typedef uint16_t (*sonata_gap_check_pkt_type_t)(uint8_t pkt_type); 598 599 // @} GAP 600 #endif // SONATA_SONATA_GAP_H_ 601