Back to home page

OSCL-LXR

 
 

    


0001 /*
0002    BlueZ - Bluetooth protocol stack for Linux
0003    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
0004 
0005    This program is free software; you can redistribute it and/or modify
0006    it under the terms of the GNU General Public License version 2 as
0007    published by the Free Software Foundation;
0008 
0009    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0010    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0011    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
0012    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
0013    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
0014    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0015    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0016    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0017 
0018    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
0019    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
0020    SOFTWARE IS DISCLAIMED.
0021 */
0022 
0023 #ifndef __SMP_H
0024 #define __SMP_H
0025 
0026 struct smp_command_hdr {
0027     __u8    code;
0028 } __packed;
0029 
0030 #define SMP_CMD_PAIRING_REQ 0x01
0031 #define SMP_CMD_PAIRING_RSP 0x02
0032 struct smp_cmd_pairing {
0033     __u8    io_capability;
0034     __u8    oob_flag;
0035     __u8    auth_req;
0036     __u8    max_key_size;
0037     __u8    init_key_dist;
0038     __u8    resp_key_dist;
0039 } __packed;
0040 
0041 #define SMP_IO_DISPLAY_ONLY 0x00
0042 #define SMP_IO_DISPLAY_YESNO    0x01
0043 #define SMP_IO_KEYBOARD_ONLY    0x02
0044 #define SMP_IO_NO_INPUT_OUTPUT  0x03
0045 #define SMP_IO_KEYBOARD_DISPLAY 0x04
0046 
0047 #define SMP_OOB_NOT_PRESENT 0x00
0048 #define SMP_OOB_PRESENT     0x01
0049 
0050 #define SMP_DIST_ENC_KEY    0x01
0051 #define SMP_DIST_ID_KEY     0x02
0052 #define SMP_DIST_SIGN       0x04
0053 #define SMP_DIST_LINK_KEY   0x08
0054 
0055 #define SMP_AUTH_NONE       0x00
0056 #define SMP_AUTH_BONDING    0x01
0057 #define SMP_AUTH_MITM       0x04
0058 #define SMP_AUTH_SC     0x08
0059 #define SMP_AUTH_KEYPRESS   0x10
0060 #define SMP_AUTH_CT2        0x20
0061 
0062 #define SMP_CMD_PAIRING_CONFIRM 0x03
0063 struct smp_cmd_pairing_confirm {
0064     __u8    confirm_val[16];
0065 } __packed;
0066 
0067 #define SMP_CMD_PAIRING_RANDOM  0x04
0068 struct smp_cmd_pairing_random {
0069     __u8    rand_val[16];
0070 } __packed;
0071 
0072 #define SMP_CMD_PAIRING_FAIL    0x05
0073 struct smp_cmd_pairing_fail {
0074     __u8    reason;
0075 } __packed;
0076 
0077 #define SMP_CMD_ENCRYPT_INFO    0x06
0078 struct smp_cmd_encrypt_info {
0079     __u8    ltk[16];
0080 } __packed;
0081 
0082 #define SMP_CMD_INITIATOR_IDENT 0x07
0083 struct smp_cmd_initiator_ident {
0084     __le16  ediv;
0085     __le64  rand;
0086 } __packed;
0087 
0088 #define SMP_CMD_IDENT_INFO  0x08
0089 struct smp_cmd_ident_info {
0090     __u8    irk[16];
0091 } __packed;
0092 
0093 #define SMP_CMD_IDENT_ADDR_INFO 0x09
0094 struct smp_cmd_ident_addr_info {
0095     __u8    addr_type;
0096     bdaddr_t bdaddr;
0097 } __packed;
0098 
0099 #define SMP_CMD_SIGN_INFO   0x0a
0100 struct smp_cmd_sign_info {
0101     __u8    csrk[16];
0102 } __packed;
0103 
0104 #define SMP_CMD_SECURITY_REQ    0x0b
0105 struct smp_cmd_security_req {
0106     __u8    auth_req;
0107 } __packed;
0108 
0109 #define SMP_CMD_PUBLIC_KEY  0x0c
0110 struct smp_cmd_public_key {
0111     __u8    x[32];
0112     __u8    y[32];
0113 } __packed;
0114 
0115 #define SMP_CMD_DHKEY_CHECK 0x0d
0116 struct smp_cmd_dhkey_check {
0117     __u8    e[16];
0118 } __packed;
0119 
0120 #define SMP_CMD_KEYPRESS_NOTIFY 0x0e
0121 struct smp_cmd_keypress_notify {
0122     __u8    value;
0123 } __packed;
0124 
0125 #define SMP_CMD_MAX     0x0e
0126 
0127 #define SMP_PASSKEY_ENTRY_FAILED    0x01
0128 #define SMP_OOB_NOT_AVAIL       0x02
0129 #define SMP_AUTH_REQUIREMENTS       0x03
0130 #define SMP_CONFIRM_FAILED      0x04
0131 #define SMP_PAIRING_NOTSUPP     0x05
0132 #define SMP_ENC_KEY_SIZE        0x06
0133 #define SMP_CMD_NOTSUPP         0x07
0134 #define SMP_UNSPECIFIED         0x08
0135 #define SMP_REPEATED_ATTEMPTS       0x09
0136 #define SMP_INVALID_PARAMS      0x0a
0137 #define SMP_DHKEY_CHECK_FAILED      0x0b
0138 #define SMP_NUMERIC_COMP_FAILED     0x0c
0139 #define SMP_BREDR_PAIRING_IN_PROGRESS   0x0d
0140 #define SMP_CROSS_TRANSP_NOT_ALLOWED    0x0e
0141 
0142 #define SMP_MIN_ENC_KEY_SIZE        7
0143 #define SMP_MAX_ENC_KEY_SIZE        16
0144 
0145 /* LTK types used in internal storage (struct smp_ltk) */
0146 enum {
0147     SMP_STK,
0148     SMP_LTK,
0149     SMP_LTK_RESPONDER,
0150     SMP_LTK_P256,
0151     SMP_LTK_P256_DEBUG,
0152 };
0153 
0154 static inline bool smp_ltk_is_sc(struct smp_ltk *key)
0155 {
0156     switch (key->type) {
0157     case SMP_LTK_P256:
0158     case SMP_LTK_P256_DEBUG:
0159         return true;
0160     }
0161 
0162     return false;
0163 }
0164 
0165 static inline u8 smp_ltk_sec_level(struct smp_ltk *key)
0166 {
0167     if (key->authenticated) {
0168         if (smp_ltk_is_sc(key))
0169             return BT_SECURITY_FIPS;
0170         else
0171             return BT_SECURITY_HIGH;
0172     }
0173 
0174     return BT_SECURITY_MEDIUM;
0175 }
0176 
0177 /* Key preferences for smp_sufficient security */
0178 enum smp_key_pref {
0179     SMP_ALLOW_STK,
0180     SMP_USE_LTK,
0181 };
0182 
0183 /* SMP Commands */
0184 int smp_cancel_and_remove_pairing(struct hci_dev *hdev, bdaddr_t *bdaddr,
0185                   u8 addr_type);
0186 bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level,
0187                  enum smp_key_pref key_pref);
0188 int smp_conn_security(struct hci_conn *hcon, __u8 sec_level);
0189 int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey);
0190 
0191 bool smp_irk_matches(struct hci_dev *hdev, const u8 irk[16],
0192              const bdaddr_t *bdaddr);
0193 int smp_generate_rpa(struct hci_dev *hdev, const u8 irk[16], bdaddr_t *rpa);
0194 int smp_generate_oob(struct hci_dev *hdev, u8 hash[16], u8 rand[16]);
0195 
0196 int smp_force_bredr(struct hci_dev *hdev, bool enable);
0197 
0198 int smp_register(struct hci_dev *hdev);
0199 void smp_unregister(struct hci_dev *hdev);
0200 
0201 #if IS_ENABLED(CONFIG_BT_SELFTEST_SMP)
0202 
0203 int bt_selftest_smp(void);
0204 
0205 #else
0206 
0207 static inline int bt_selftest_smp(void)
0208 {
0209     return 0;
0210 }
0211 
0212 #endif
0213 
0214 #endif /* __SMP_H */