1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 #ifndef H_BLE_SM_ 21 #define H_BLE_SM_ 22 23 #include <stdint.h> 24 #include "syscfg/syscfg.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #define BLE_SM_ERR_PASSKEY 0x01 31 #define BLE_SM_ERR_OOB 0x02 32 #define BLE_SM_ERR_AUTHREQ 0x03 33 #define BLE_SM_ERR_CONFIRM_MISMATCH 0x04 34 #define BLE_SM_ERR_PAIR_NOT_SUPP 0x05 35 #define BLE_SM_ERR_ENC_KEY_SZ 0x06 36 #define BLE_SM_ERR_CMD_NOT_SUPP 0x07 37 #define BLE_SM_ERR_UNSPECIFIED 0x08 38 #define BLE_SM_ERR_REPEATED 0x09 39 #define BLE_SM_ERR_INVAL 0x0a 40 #define BLE_SM_ERR_DHKEY 0x0b 41 #define BLE_SM_ERR_NUMCMP 0x0c 42 #define BLE_SM_ERR_ALREADY 0x0d 43 #define BLE_SM_ERR_CROSS_TRANS 0x0e 44 #define BLE_SM_ERR_MAX_PLUS_1 0x0f 45 46 #define BLE_SM_PAIR_ALG_JW 0 47 #define BLE_SM_PAIR_ALG_PASSKEY 1 48 #define BLE_SM_PAIR_ALG_OOB 2 49 #define BLE_SM_PAIR_ALG_NUMCMP 3 50 51 #define BLE_SM_PAIR_KEY_DIST_ENC 0x01 52 #define BLE_SM_PAIR_KEY_DIST_ID 0x02 53 #define BLE_SM_PAIR_KEY_DIST_SIGN 0x04 54 #define BLE_SM_PAIR_KEY_DIST_LINK 0x08 55 #define BLE_SM_PAIR_KEY_DIST_RESERVED 0xf0 56 57 #define BLE_SM_IO_CAP_DISP_ONLY 0x00 58 #define BLE_SM_IO_CAP_DISP_YES_NO 0x01 59 #define BLE_SM_IO_CAP_KEYBOARD_ONLY 0x02 60 #define BLE_SM_IO_CAP_NO_IO 0x03 61 #define BLE_SM_IO_CAP_KEYBOARD_DISP 0x04 62 #define BLE_SM_IO_CAP_RESERVED 0x05 63 64 #define BLE_SM_PAIR_OOB_NO 0x00 65 #define BLE_SM_PAIR_OOB_YES 0x01 66 #define BLE_SM_PAIR_OOB_RESERVED 0x02 67 68 #define BLE_SM_PAIR_AUTHREQ_BOND 0x01 69 #define BLE_SM_PAIR_AUTHREQ_MITM 0x04 70 #define BLE_SM_PAIR_AUTHREQ_SC 0x08 71 #define BLE_SM_PAIR_AUTHREQ_KEYPRESS 0x10 72 #define BLE_SM_PAIR_AUTHREQ_RESERVED 0xe2 73 74 #define BLE_SM_PAIR_KEY_SZ_MIN 7 75 #define BLE_SM_PAIR_KEY_SZ_MAX 16 76 77 /* 78 * The security manager asks the application to perform a key generation 79 * action. The application passes the passkey back to SM via 80 * ble_sm_inject_io(). 81 */ 82 #define BLE_SM_IOACT_NONE 0 83 #define BLE_SM_IOACT_OOB 1 84 #define BLE_SM_IOACT_INPUT 2 85 #define BLE_SM_IOACT_DISP 3 86 #define BLE_SM_IOACT_NUMCMP 4 87 #define BLE_SM_IOACT_OOB_SC 5 88 #define BLE_SM_IOACT_MAX_PLUS_ONE 6 89 90 struct ble_sm_sc_oob_data { 91 /** Random Number. */ 92 uint8_t r[16]; 93 94 /** Confirm Value. */ 95 uint8_t c[16]; 96 }; 97 98 struct ble_sm_io { 99 uint8_t action; 100 union { 101 uint32_t passkey; 102 uint8_t oob[16]; 103 uint8_t numcmp_accept; 104 struct { 105 struct ble_sm_sc_oob_data *local; 106 struct ble_sm_sc_oob_data *remote; 107 } oob_sc_data; 108 }; 109 }; 110 111 int ble_sm_sc_oob_generate_data(struct ble_sm_sc_oob_data *oob_data); 112 113 #if NIMBLE_BLE_SM 114 int ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey); 115 #else 116 #define ble_sm_inject_io(conn_handle, pkey) \ 117 ((void)(conn_handle), BLE_HS_ENOTSUP) 118 #endif 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 #endif 125