1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
26
27
28
29
30
37
44
45
46
47
48
61
62
63
64
65
75
76
80
81
82
83
84
85
86
87
105
106
107
108
109
110
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
134
137
141
142
143
144
145
146
147
148
149
150
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
173
174
175
176
177
178
179
180
181
182
183
186
187
188
189
190
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
225
226
227
228
229
233
234
235
236
237
238
239
240
244
245
246
250
251
252
253
254
255
261
263
264
265
266
270
287
288
292
297
298
299
309
310
314
319
320
324
329
330
334
339
340
344
349
350
354
359
360
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
396
397
398
399
400
401
402
403
404
405
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
433
434
435
436
437
441
447
448
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
471
472
473
474
475
476
477
486
487
488
492
495
496
497
498
499
503
514
515
519
524
525
529
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
568
569
570
571
572
573
574
575
576
577
578
583
584
585
586
593
594
595
596
597
598
599
600
607
608
611
612
613
614
615
616
619
620
621
622
623
624
625
632
633
634
635
636
637
638
645
646
647
650
651
652
653
654
655
658
659
660
661
662
663
664
665
672
673
674
675
676
680
681
682
683
684
685
686
687
691
692
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
716
717
718
719
720
721
722
726
727
728
729
730
731
732
733
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
761
762
763
764
765
768
769
770
771
772
773
774
775
776
778
782
783
784
785
786
787
791
792
793
794
795
796
797
798
802
803
804
805
808
809
810
814
815
816
817
818
819
820
821
825
826
829
830
831
832
833
837
838
839
840
841
842
843
844
845
849
850
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
877
878
879
884
885
886
887
888
889
890
891
892
893
894
899
900
901
902
903
904
905
913
914
916
917
918
919
920
924
935
936
941
942
943
944
945
946
947
948
949
950
951
952
953
955
958
959
960
961
962
963
965
975
976
977
982
983
984
985
986
987
988
989
992
993
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1095
1096
1097
1098
1099
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1121
1122
1123
1124
1125
1126
1130
1131
1132
1133
1134
1135
1136
1137
1140
1141
1144
1145
1146
1147
1148
1149
1150
1151
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1176
1177
1178
1182
1183
1184
1185
1186
1187
1188
1193
1194
1197
1198
1199
1200
1204
1211
1212
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1249
1250
1253
1256
1261
1262
1263
1264
1265
1267
1272
1273
1274
1277
1278
1279
1282
1283
1284
1285
1289
1290
1291
1292
1293
1294
1295
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1322
1323
1338
1339
1340
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1402
1408
1413
1414
1415
1416
1419
1420
1421
1425
1426
1427
1428
1429
1434
1435
1436
1437
1438
1439
1445
1446
1449
1450
1451
1452
1453
1454
1457
1458
1459
1460
1461
1462
1463
1468
1469
1470
1471
1472
1473
1478
1482
1483
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1502
1509
1510
1515
1521
1522
1527
1535
1536
1537
1538
1539
1540
1541
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1585
1586
1587
1588
1589
1595
1596
1597
1598
1599
1606
1607
1608
1609
1613
1618
1623
1627
1631
1632
1633
1634
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1679
1686
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1729
1730
1731
1736
1737
1740
1741
1747
1748
1749
1750
1757
1761
1762
1763
1764
1765
1766
1767
1772
1773
1774
1775
1776
1777
1778
1784
1785
1786
1787
1788
1791
1792
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1814
1815
1816
1817
1818
1819
1820
1821
1822
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1877
1878
1879
1880
1881
1882
1889
1890
1894
1895
1896
1897
1898
1899
1900
1901
1906
1907
1912
1913
1914
1915
1916
1917
1918
1919
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2014
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2050
2051
2052
2053
2054
2057
2058
2059
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2152
2153
2154
2155
2156
2157
2158
2159
2160
2165
2178
2179
2184
2193
2194
/* ... */
#include <string.h>
#include "device/interop.h"
#include "common/bt_target.h"
#include "btm_int.h"
#include "stack/l2c_api.h"
#include "smp_int.h"
#include "p_256_ecc_pp.h"7 includes
#if SMP_INCLUDED == TRUE
const UINT8 smp_association_table[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = {
{ {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY},
{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY},
{SMP_MODEL_KEY_NOTIF, SMP_MODEL_KEY_NOTIF, SMP_MODEL_PASSKEY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF},
{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY},
{SMP_MODEL_KEY_NOTIF, SMP_MODEL_KEY_NOTIF, SMP_MODEL_PASSKEY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF}
}{...},
{ {SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF},
{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_KEY_NOTIF},
{SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY},
{SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_ENCRYPTION_ONLY},
{SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_KEY_NOTIF, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}
}{...}
}{...};
#define SMP_KEY_DIST_TYPE_MAX 4
const tSMP_ACT smp_distribute_act [] = {
#if (BLE_INCLUDED == TRUE)
smp_generate_ltk,
smp_send_id_info,
smp_generate_csrk,
smp_set_derive_link_key/* ... */
#else
NULL,
NULL,
NULL,
NULL/* ... */
#endif
}{...};
extern UINT8 bta_dm_co_ble_get_accept_auth_enable(void);
extern UINT8 bta_dm_co_ble_get_auth_req(void);
static bool lmp_version_below(BD_ADDR bda, uint8_t version)
{
tACL_CONN *acl = btm_bda_to_acl(bda, BT_TRANSPORT_LE);
if (acl == NULL || acl->lmp_version == 0) {
SMP_TRACE_WARNING("%s cannot retrieve LMP version...", __func__);
return false;
}{...}
SMP_TRACE_DEBUG("%s LMP version %d < %d", __func__, acl->lmp_version, version);
return acl->lmp_version < version;
}{ ... }
/* ... */
static void smp_update_key_mask (tSMP_CB *p_cb, UINT8 key_type, BOOLEAN recv)
{
SMP_TRACE_DEBUG("%s before update role=%d recv=%d local_i_key = %02x, local_r_key = %02x\n",
__func__, p_cb->role, recv, p_cb->local_i_key, p_cb->local_r_key);
if (((p_cb->le_secure_connections_mode_is_used) ||
(p_cb->smp_over_br)) &&
((key_type == SMP_SEC_KEY_TYPE_ENC) || (key_type == SMP_SEC_KEY_TYPE_LK))) {
/* ... */
p_cb->local_i_key &= ~key_type;
p_cb->local_r_key &= ~key_type;
}{...} else if (p_cb->role == HCI_ROLE_SLAVE) {
if (recv) {
p_cb->local_i_key &= ~key_type;
}{...} else {
p_cb->local_r_key &= ~key_type;
}{...}
}{...} else {
if (recv) {
p_cb->local_r_key &= ~key_type;
}{...} else {
p_cb->local_i_key &= ~key_type;
}{...}
}{...}
SMP_TRACE_DEBUG("updated local_i_key = %02x, local_r_key = %02x\n", p_cb->local_i_key,
p_cb->local_r_key);
}{ ... }
/* ... */
void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tSMP_EVT_DATA cb_data;
tSMP_STATUS callback_rc;
SMP_TRACE_DEBUG("%s p_cb->cb_evt=%d\n", __func__, p_cb->cb_evt);
if (p_cb->p_callback && p_cb->cb_evt != 0) {
switch (p_cb->cb_evt) {
case SMP_IO_CAP_REQ_EVT:
cb_data.io_req.auth_req = p_cb->peer_auth_req;
cb_data.io_req.oob_data = SMP_OOB_NONE;
cb_data.io_req.io_cap = SMP_DEFAULT_IO_CAPS;
cb_data.io_req.max_key_size = SMP_MAX_ENC_KEY_SIZE;
cb_data.io_req.init_keys = p_cb->local_i_key ;
cb_data.io_req.resp_keys = p_cb->local_r_key ;
SMP_TRACE_DEBUG ( "io_cap = %d", cb_data.io_req.io_cap);
break;
...
case SMP_NC_REQ_EVT:
cb_data.passkey = p_data->passkey;
break;...
case SMP_SC_OOB_REQ_EVT:
cb_data.req_oob_type = p_data->req_oob_type;
break;...
case SMP_SC_LOC_OOB_DATA_UP_EVT:
cb_data.loc_oob_data = p_cb->sc_oob_data.loc_oob_data;
break;
...
case SMP_BR_KEYS_REQ_EVT:
cb_data.io_req.auth_req = 0;
cb_data.io_req.oob_data = SMP_OOB_NONE;
cb_data.io_req.io_cap = 0;
cb_data.io_req.max_key_size = SMP_MAX_ENC_KEY_SIZE;
cb_data.io_req.init_keys = SMP_BR_SEC_DEFAULT_KEY;
cb_data.io_req.resp_keys = SMP_BR_SEC_DEFAULT_KEY;
break;
...
default:
break;...
}{...}
callback_rc = (*p_cb->p_callback)(p_cb->cb_evt, p_cb->pairing_bda, &cb_data);
SMP_TRACE_DEBUG("callback_rc=%d p_cb->cb_evt=%d\n", callback_rc, p_cb->cb_evt );
if (callback_rc == SMP_SUCCESS) {
switch (p_cb->cb_evt) {
case SMP_IO_CAP_REQ_EVT:
p_cb->loc_auth_req = cb_data.io_req.auth_req;
p_cb->local_io_capability = cb_data.io_req.io_cap;
p_cb->loc_oob_flag = cb_data.io_req.oob_data;
p_cb->loc_enc_size = cb_data.io_req.max_key_size;
p_cb->local_i_key = cb_data.io_req.init_keys;
p_cb->local_r_key = cb_data.io_req.resp_keys;
if (!(p_cb->loc_auth_req & SMP_AUTH_BOND)) {
SMP_TRACE_WARNING ("Non bonding: No keys will be exchanged");
p_cb->local_i_key = 0;
p_cb->local_r_key = 0;
}{...}
SMP_TRACE_DEBUG ("rcvd auth_req: 0x%02x, io_cap: %d \
loc_oob_flag: %d loc_enc_size: %d,"
"local_i_key: 0x%02x, local_r_key: 0x%02x\n",
p_cb->loc_auth_req, p_cb->local_io_capability, p_cb->loc_oob_flag,
p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key);
p_cb->secure_connections_only_mode_required =
(btm_cb.security_mode == BTM_SEC_MODE_SC) ? TRUE : FALSE;
if (p_cb->secure_connections_only_mode_required) {
p_cb->loc_auth_req |= SMP_SC_SUPPORT_BIT;
}{...}
if (!(p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)
|| lmp_version_below(p_cb->pairing_bda, HCI_PROTO_VERSION_4_2)
|| interop_match(INTEROP_DISABLE_LE_SECURE_CONNECTIONS,
(const bt_bdaddr_t *)&p_cb->pairing_bda)) {
p_cb->loc_auth_req &= ~SMP_KP_SUPPORT_BIT;
p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK;
p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
}{...}
SMP_TRACE_DEBUG("set auth_req: 0x%02x, local_i_key: 0x%02x, local_r_key: 0x%02x\n",
p_cb->loc_auth_req, p_cb->local_i_key, p_cb->local_r_key);
smp_sm_event(p_cb, SMP_IO_RSP_EVT, NULL);
break;
#if (CLASSIC_BT_INCLUDED == TRUE)...
case SMP_BR_KEYS_REQ_EVT:
p_cb->loc_enc_size = cb_data.io_req.max_key_size;
p_cb->local_i_key = cb_data.io_req.init_keys;
p_cb->local_r_key = cb_data.io_req.resp_keys;
p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK;
p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
SMP_TRACE_WARNING ( "for SMP over BR max_key_size: 0x%02x,\
local_i_key: 0x%02x, local_r_key: 0x%02x\n",
p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key);
smp_br_state_machine_event(p_cb, SMP_BR_KEYS_RSP_EVT, NULL);
break;/* ... */
#endif
}{...}
}{...}
}{...}
if (!p_cb->cb_evt && p_cb->discard_sec_req) {
p_cb->discard_sec_req = FALSE;
smp_sm_event(p_cb, SMP_DISCARD_SEC_REQ_EVT, NULL);
}{...}
SMP_TRACE_DEBUG("%s return\n", __func__);
}{ ... }
/* ... */
void smp_send_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
p_cb->status = *(UINT8 *)p_data;
p_cb->failure = *(UINT8 *)p_data;
SMP_TRACE_DEBUG("%s status=%d failure=%d ", __func__, p_cb->status, p_cb->failure);
if (p_cb->status <= SMP_MAX_FAIL_RSN_PER_SPEC && p_cb->status != SMP_SUCCESS) {
smp_send_cmd(SMP_OPCODE_PAIRING_FAILED, p_cb);
p_cb->wait_for_authorization_complete = TRUE;
}{...}
}{ ... }
/* ... */
void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
#if (BLE_INCLUDED == TRUE)
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda);
if (p_dev_rec) {
btm_sec_clear_ble_keys(p_dev_rec);
}{...}
/* ... */#endif
/* ... */
smp_send_cmd(SMP_OPCODE_PAIRING_REQ, p_cb);
}{ ... }
/* ... */
void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
#if (BLE_INCLUDED == TRUE)
p_cb->local_i_key &= p_cb->peer_i_key;
p_cb->local_r_key &= p_cb->peer_r_key;
if (smp_send_cmd (SMP_OPCODE_PAIRING_RSP, p_cb)) {
if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) {
smp_use_oob_private_key(p_cb, NULL);
}{...} else {
smp_decide_association_model(p_cb, NULL);
}{...}
}{...}
#endif/* ... */
}{ ... }
/* ... */
void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb);
}{ ... }
#if 0
/* ... */
void smp_send_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
smp_send_cmd(SMP_OPCODE_INIT, p_cb);
}{...}
/* ... */#endif
/* ... */
void smp_send_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
smp_send_cmd(SMP_OPCODE_RAND, p_cb);
}{ ... }
/* ... */
void smp_send_pair_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
smp_send_cmd(SMP_OPCODE_PAIR_PUBLIC_KEY, p_cb);
}{ ... }
/* ... */
void smp_send_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s", __func__);
smp_send_cmd(SMP_OPCODE_PAIR_COMMITM, p_cb);
}{ ... }
/* ... */
void smp_send_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s", __func__);
smp_send_cmd(SMP_OPCODE_PAIR_DHKEY_CHECK, p_cb);
}{ ... }
/* ... */
void smp_send_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
p_cb->local_keypress_notification = *(UINT8 *) p_data;
smp_send_cmd(SMP_OPCODE_PAIR_KEYPR_NOTIF, p_cb);
}{ ... }
/* ... */
void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tBTM_LE_LENC_KEYS le_key;
SMP_TRACE_DEBUG("%s p_cb->loc_enc_size = %d\n", __func__, p_cb->loc_enc_size);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, FALSE);
smp_send_cmd(SMP_OPCODE_ENCRYPT_INFO, p_cb);
smp_send_cmd(SMP_OPCODE_MASTER_ID, p_cb);
memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN);
le_key.div = p_cb->div;
le_key.key_size = p_cb->loc_enc_size;
le_key.sec_level = p_cb->sec_level;
#if (BLE_INCLUDED == TRUE)
if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) {
btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC,
(tBTM_LE_KEY_VALUE *)&le_key, TRUE);
}{...}
SMP_TRACE_DEBUG ("%s\n", __func__);
smp_key_distribution(p_cb, NULL);/* ... */
#endif
}{ ... }
/* ... */
void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, FALSE);
smp_send_cmd(SMP_OPCODE_IDENTITY_INFO, p_cb);
smp_send_cmd(SMP_OPCODE_ID_ADDR, p_cb);
#if (BLE_INCLUDED == TRUE)
tBTM_LE_KEY_VALUE le_key;
if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) {
btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LID,
&le_key, TRUE);
}{...}
/* ... */#endif
smp_key_distribution_by_transport(p_cb, NULL);
}{ ... }
#if (BLE_INCLUDED == TRUE)
/* ... */
void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tBTM_LE_LCSRK_KEYS key;
SMP_TRACE_DEBUG("%s\n", __func__);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, FALSE);
if (smp_send_cmd(SMP_OPCODE_SIGN_INFO, p_cb)) {
key.div = p_cb->div;
key.sec_level = p_cb->sec_level;
key.counter = 0;
memcpy (key.csrk, p_cb->csrk, BT_OCTET16_LEN);
btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LCSRK, (tBTM_LE_KEY_VALUE *)&key, TRUE);
}{...}
smp_key_distribution_by_transport(p_cb, NULL);
}{ ... }
/* ... */
void smp_send_ltk_reply(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s", __func__);
btm_ble_ltk_request_reply(p_cb->pairing_bda, TRUE, p_data->key.p_data);
}{ ... }
/* ... */
void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tBTM_LE_AUTH_REQ auth_req = *(tBTM_LE_AUTH_REQ *)p_data;
tBTM_BLE_SEC_REQ_ACT sec_req_act;
UINT8 reason;
SMP_TRACE_DEBUG("%s auth_req=0x%x", __func__, auth_req);
p_cb->cb_evt = 0;
btm_ble_link_sec_check(p_cb->pairing_bda, auth_req, &sec_req_act);
SMP_TRACE_DEBUG("%s sec_req_act=0x%x", __func__, sec_req_act);
switch (sec_req_act) {
case BTM_BLE_SEC_REQ_ACT_ENCRYPT:
SMP_TRACE_DEBUG("%s BTM_BLE_SEC_REQ_ACT_ENCRYPT", __func__);
smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL);
break;
...
case BTM_BLE_SEC_REQ_ACT_PAIR:
p_cb->secure_connections_only_mode_required =
(btm_cb.security_mode == BTM_SEC_MODE_SC) ? TRUE : FALSE;
if (p_cb->secure_connections_only_mode_required &&
(auth_req & SMP_SC_SUPPORT_BIT) == 0) {
reason = SMP_PAIR_AUTH_FAIL;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...} else {
p_cb->peer_auth_req = auth_req;
p_cb->local_r_key = p_cb->local_i_key = SMP_SEC_DEFAULT_KEY ;
p_cb->cb_evt = SMP_SEC_REQUEST_EVT;
}{...}
break;
...
case BTM_BLE_SEC_REQ_ACT_DISCARD:
p_cb->discard_sec_req = TRUE;
break;
...
default:
break;...
}{...}
}{ ... }
#endif/* ... */
/* ... */
void smp_proc_sec_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 res = *(UINT8 *)p_data;
SMP_TRACE_DEBUG("%s", __func__);
if (res != SMP_SUCCESS) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, p_data);
}{...} else {
p_cb->cb_evt = SMP_IO_CAP_REQ_EVT;
}{...}
}{ ... }
/* ... */
void smp_proc_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s", __func__);
p_cb->status = *(UINT8 *)p_data;
}{ ... }
/* ... */
uint16_t smp_get_auth_mode (tSMP_ASSO_MODEL model)
{
SMP_TRACE_DEBUG("%s model %d", __func__, model);
uint16_t auth = 0;
if (model == SMP_MODEL_ENCRYPTION_ONLY || model == SMP_MODEL_SEC_CONN_JUSTWORKS) {
if(model == SMP_MODEL_SEC_CONN_JUSTWORKS) {
auth |= SMP_SC_SUPPORT_BIT;
}{...}
}{...} else if (model <= SMP_MODEL_KEY_NOTIF) {
auth |= SMP_AUTH_YN_BIT;
}{...} else if (model <= SMP_MODEL_SEC_CONN_OOB) {
auth |= SMP_SC_SUPPORT_BIT;
auth |= SMP_AUTH_YN_BIT;
}{...} else {
auth = 0;
}{...}
return auth;
}{ ... }
#if (BLE_INCLUDED == TRUE)
/* ... */
void smp_proc_pair_cmd(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_ENC_KEY_SIZE;
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda);
SMP_TRACE_DEBUG("%s\n", __func__);
if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) {
btm_sec_clear_ble_keys(p_dev_rec);
}{...}
p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR;
STREAM_TO_UINT8(p_cb->peer_io_caps, p);
STREAM_TO_UINT8(p_cb->peer_oob_flag, p);
STREAM_TO_UINT8(p_cb->peer_auth_req, p);
STREAM_TO_UINT8(p_cb->peer_enc_size, p);
STREAM_TO_UINT8(p_cb->peer_i_key, p);
STREAM_TO_UINT8(p_cb->peer_r_key, p);
if (smp_command_has_invalid_parameters(p_cb)) {
reason = SMP_INVALID_PARAMETERS;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
p_cb->accept_specified_sec_auth = bta_dm_co_ble_get_accept_auth_enable();
p_cb->origin_loc_auth_req = bta_dm_co_ble_get_auth_req();
if (p_cb->role == HCI_ROLE_SLAVE) {
if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) {
p_cb->local_i_key = p_cb->peer_i_key;
p_cb->local_r_key = p_cb->peer_r_key;
p_cb->cb_evt = SMP_SEC_REQUEST_EVT;
}{...} else {
p_cb->local_i_key &= p_cb->peer_i_key;
p_cb->local_r_key &= p_cb->peer_r_key;
p_cb->selected_association_model = smp_select_association_model(p_cb);
if (p_cb->secure_connections_only_mode_required &&
(!(p_cb->le_secure_connections_mode_is_used) ||
(p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) {
SMP_TRACE_ERROR("%s pairing failed - slave requires secure connection only mode",
__func__);
reason = SMP_PAIR_AUTH_FAIL;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
uint16_t auth = smp_get_auth_mode(p_cb->selected_association_model);
if(p_cb->peer_auth_req & p_cb->loc_auth_req & SMP_AUTH_GEN_BOND) {
auth |= SMP_AUTH_GEN_BOND;
}{...}
p_cb->auth_mode = auth;
if (p_cb->accept_specified_sec_auth) {
if ((auth & p_cb->origin_loc_auth_req) != p_cb->origin_loc_auth_req ) {
SMP_TRACE_ERROR("%s pairing failed - slave requires auth is 0x%x but peer auth is 0x%x local auth is 0x%x",
__func__, p_cb->origin_loc_auth_req, p_cb->peer_auth_req, p_cb->loc_auth_req);
if (BTM_IsAclConnectionUp(p_cb->pairing_bda, BT_TRANSPORT_LE)) {
btm_remove_acl (p_cb->pairing_bda, BT_TRANSPORT_LE);
}{...}
reason = SMP_PAIR_AUTH_FAIL;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
}{...}
if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB && p_cb->loc_oob_flag == SMP_OOB_PRESENT) {
if (smp_request_oob_data(p_cb)) {
return;
}{...}
}{...} else {
smp_send_pair_rsp(p_cb, NULL);
}{...}
}{...}
}{...} else {
p_cb->selected_association_model = smp_select_association_model(p_cb);
if (p_cb->secure_connections_only_mode_required &&
(!(p_cb->le_secure_connections_mode_is_used) ||
(p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) {
SMP_TRACE_ERROR ("Master requires secure connection only mode \
but it can't be provided -> Master fails pairing");
reason = SMP_PAIR_AUTH_FAIL;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
uint16_t auth = smp_get_auth_mode(p_cb->selected_association_model);
if(p_cb->peer_auth_req & p_cb->loc_auth_req & SMP_AUTH_GEN_BOND) {
auth |= SMP_AUTH_GEN_BOND;
}{...}
p_cb->auth_mode = auth;
if (p_cb->accept_specified_sec_auth) {
if ((auth & p_cb->origin_loc_auth_req) != p_cb->origin_loc_auth_req ) {
SMP_TRACE_ERROR("%s pairing failed - master requires auth is 0x%x but peer auth is 0x%x local auth is 0x%x",
__func__, p_cb->origin_loc_auth_req, p_cb->peer_auth_req, p_cb->loc_auth_req);
if (BTM_IsAclConnectionUp(p_cb->pairing_bda, BT_TRANSPORT_LE)) {
btm_remove_acl (p_cb->pairing_bda, BT_TRANSPORT_LE);
}{...}
reason = SMP_PAIR_AUTH_FAIL;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
}{...}
if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB && p_cb->loc_oob_flag == SMP_OOB_PRESENT) {
if (smp_request_oob_data(p_cb)) {
return;
}{...}
}{...} else {
smp_decide_association_model(p_cb, NULL);
}{...}
}{...}
}{ ... }
#endif/* ... */
/* ... */
void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s\n", __func__);
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
if (p != NULL) {
STREAM_TO_ARRAY(p_cb->rconfirm, p, BT_OCTET16_LEN);
}{...}
p_cb->flags |= SMP_PAIR_FLAGS_CMD_CONFIRM;
}{ ... }
#if 0
/* ... */
void smp_proc_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s", __func__);
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN);
}{...}
/* ... */#endif
/* ... */
void smp_proc_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s\n", __func__);
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
STREAM_TO_ARRAY(p_cb->rrand, p, BT_OCTET16_LEN);
}{ ... }
/* ... */
void smp_process_pairing_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s", __func__);
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
STREAM_TO_ARRAY(p_cb->peer_publ_key.x, p, BT_OCTET32_LEN);
STREAM_TO_ARRAY(p_cb->peer_publ_key.y, p, BT_OCTET32_LEN);
/* ... */
if ((memcmp(p_cb->loc_publ_key.x, p_cb->peer_publ_key.x, sizeof(BT_OCTET32)) == 0)) {
p_cb->status = SMP_PAIR_AUTH_FAIL;
p_cb->failure = SMP_PAIR_AUTH_FAIL;
reason = SMP_PAIR_AUTH_FAIL;
SMP_TRACE_ERROR("%s, Peer and own device cannot have same public key.", __func__);
smp_sm_event(p_cb, SMP_PAIRING_FAILED_EVT, &reason);
return ;
}{...}
/* ... */
if (!ECC_CheckPointIsInElliCur_P256((Point *)&p_cb->peer_publ_key)) {
SMP_TRACE_ERROR("%s, Invalid Public key.", __func__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...}
p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY;
smp_wait_for_both_public_keys(p_cb, NULL);
}{ ... }
/* ... */
void smp_process_pairing_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s", __func__);
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_COMM;
if (p != NULL) {
STREAM_TO_ARRAY(p_cb->remote_commitment, p, BT_OCTET16_LEN);
}{...}
}{ ... }
/* ... */
void smp_process_dhkey_check(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s", __func__);
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
if (p != NULL) {
STREAM_TO_ARRAY(p_cb->remote_dhkey_check, p, BT_OCTET16_LEN);
}{...}
p_cb->flags |= SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK;
}{ ... }
/* ... */
void smp_process_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s", __func__);
p_cb->status = *(UINT8 *)p_data;
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
if (p != NULL) {
STREAM_TO_UINT8(p_cb->peer_keypress_notification, p);
}{...} else {
p_cb->peer_keypress_notification = BTM_SP_KEY_OUT_OF_RANGE;
}{...}
p_cb->cb_evt = SMP_PEER_KEYPR_NOT_EVT;
}{ ... }
#if (CLASSIC_BT_INCLUDED == TRUE)
/* ... */
void smp_br_process_pairing_command(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_ENC_KEY_SIZE;
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda);
SMP_TRACE_DEBUG("%s", __func__);
if (!p_dev_rec->new_encryption_key_is_p256 && p_cb->role == HCI_ROLE_SLAVE) {
reason = SMP_XTRANS_DERIVE_NOT_ALLOW;
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
return;
}{...}
#if (BLE_INCLUDED == TRUE)
if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) {
btm_sec_clear_ble_keys(p_dev_rec);
}{...}
/* ... */#endif
p_cb->flags |= SMP_PAIR_FLAG_ENC_AFTER_PAIR;
STREAM_TO_UINT8(p_cb->peer_io_caps, p);
STREAM_TO_UINT8(p_cb->peer_oob_flag, p);
STREAM_TO_UINT8(p_cb->peer_auth_req, p);
STREAM_TO_UINT8(p_cb->peer_enc_size, p);
STREAM_TO_UINT8(p_cb->peer_i_key, p);
STREAM_TO_UINT8(p_cb->peer_r_key, p);
if (smp_command_has_invalid_parameters(p_cb)) {
reason = SMP_INVALID_PARAMETERS;
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
return;
}{...}
p_cb->local_i_key = p_cb->peer_i_key;
p_cb->local_r_key = p_cb->peer_r_key;
if (p_cb->role == HCI_ROLE_SLAVE) {
p_dev_rec->new_encryption_key_is_p256 = FALSE;
p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT;
}{...} else {
SMP_TRACE_DEBUG("%s master rcvs valid PAIRING RESPONSE."
" Supposed to move to key distribution phase. ", __func__);
}{...}
/* ... */
p_cb->peer_auth_req |= SMP_AUTH_BOND;
p_cb->loc_auth_req |= SMP_AUTH_BOND;
}{...}
/* ... */
void smp_br_process_security_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 res = *(UINT8 *)p_data;
SMP_TRACE_DEBUG("%s", __func__);
if (res != SMP_SUCCESS) {
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, p_data);
}{...} else {
p_cb->cb_evt = SMP_BR_KEYS_REQ_EVT;
}{...}
}{...}
/* ... */
void smp_br_check_authorization_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 reason = SMP_SUCCESS;
SMP_TRACE_DEBUG("%s rcvs i_keys=0x%x r_keys=0x%x "
"(i-initiator r-responder)", __FUNCTION__, p_cb->local_i_key,
p_cb->local_r_key);
p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK;
p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
/* ... */
if (p_cb->role == HCI_ROLE_MASTER) {
p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK);
}{...}
SMP_TRACE_DEBUG("%s rcvs upgrades: i_keys=0x%x r_keys=0x%x "
"(i-initiator r-responder)", __FUNCTION__, p_cb->local_i_key,
p_cb->local_r_key);
if (
/* ... */
(p_cb->local_i_key || p_cb->local_r_key)) {
smp_br_state_machine_event(p_cb, SMP_BR_BOND_REQ_EVT, NULL);
if (p_cb->role == HCI_ROLE_MASTER && p_cb->local_r_key == 0) {
smp_key_distribution_by_transport(p_cb, NULL);
}{...}
}{...} else {
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
}{...}
}{...}
/* ... */
void smp_br_select_next_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 reason = SMP_SUCCESS;
SMP_TRACE_DEBUG("%s role=%d (0-master) r_keys=0x%x i_keys=0x%x",
__func__, p_cb->role, p_cb->local_r_key, p_cb->local_i_key);
if (p_cb->role == HCI_ROLE_SLAVE ||
(!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) {
smp_key_pick_key(p_cb, p_data);
}{...}
if (!p_cb->local_i_key && !p_cb->local_r_key) {
if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) {
if (p_cb->total_tx_unacked == 0) {
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
}{...} else {
p_cb->wait_for_authorization_complete = TRUE;
}{...}
}{...}
}{...}
}{...}
/* ... */#endif
#if (BLE_INCLUDED == TRUE)
/* ... */
void smp_proc_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
SMP_TRACE_DEBUG("%s\n", __func__);
STREAM_TO_ARRAY(p_cb->ltk, p, BT_OCTET16_LEN);
smp_key_distribution(p_cb, NULL);
}{ ... }
#endif/* ... */
/* ... */
void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
tBTM_LE_PENC_KEYS le_key;
SMP_TRACE_DEBUG("%s\np_cb->peer_auth_req = %d,p_cb->loc_auth_req= %d\n", __func__,
p_cb->peer_auth_req, p_cb->loc_auth_req);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, TRUE);
STREAM_TO_UINT16(le_key.ediv, p);
STREAM_TO_ARRAY(le_key.rand, p, BT_OCTET8_LEN );
memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN);
le_key.sec_level = p_cb->sec_level;
le_key.key_size = p_cb->loc_enc_size;
#if (BLE_INCLUDED == TRUE)
if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) {
btm_sec_save_le_key(p_cb->pairing_bda,
BTM_LE_KEY_PENC,
(tBTM_LE_KEY_VALUE *)&le_key, TRUE);
}{...}
smp_key_distribution(p_cb, NULL);/* ... */
#endif
}{ ... }
/* ... */
void smp_proc_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
SMP_TRACE_DEBUG("%s", __func__);
STREAM_TO_ARRAY (p_cb->tk, p, BT_OCTET16_LEN);
smp_key_distribution_by_transport(p_cb, NULL);
}{ ... }
/* ... */
void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = (UINT8 *)p_data;
tBTM_LE_PID_KEYS pid_key;
SMP_TRACE_DEBUG("%s", __func__);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, TRUE);
STREAM_TO_UINT8(pid_key.addr_type, p);
STREAM_TO_BDADDR(pid_key.static_addr, p);
memcpy(pid_key.irk, p_cb->tk, BT_OCTET16_LEN);
p_cb->id_addr_rcvd = TRUE;
p_cb->id_addr_type = pid_key.addr_type;
memcpy(p_cb->id_addr, pid_key.static_addr, BD_ADDR_LEN);
#if (BLE_INCLUDED == TRUE)
if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) {
btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PID,
(tBTM_LE_KEY_VALUE *)&pid_key, TRUE);
}{...}
#endif/* ... */
smp_key_distribution_by_transport(p_cb, NULL);
}{ ... }
/* ... */
void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
#if (BLE_INCLUDED == TRUE)
tBTM_LE_PCSRK_KEYS le_key;
SMP_TRACE_DEBUG("%s", __func__);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, TRUE);
le_key.sec_level = p_cb->sec_level;
memcpy (le_key.csrk, p_data, BT_OCTET16_LEN);
le_key.counter = 0;
if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) {
btm_sec_save_le_key(p_cb->pairing_bda,
BTM_LE_KEY_PCSRK,
(tBTM_LE_KEY_VALUE *)&le_key, TRUE);
}{...}
/* ... */#endif
smp_key_distribution_by_transport(p_cb, NULL);
}{ ... }
/* ... */
void smp_proc_compare(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 reason;
SMP_TRACE_DEBUG("%s\n", __func__);
if (!memcmp(p_cb->rconfirm, p_data->key.p_data, BT_OCTET16_LEN)) {
if ( p_cb->peer_enc_size < p_cb->loc_enc_size) {
p_cb->loc_enc_size = p_cb->peer_enc_size;
}{...}
if (p_cb->role == HCI_ROLE_SLAVE) {
smp_sm_event(p_cb, SMP_RAND_EVT, NULL);
}{...} else {
p_cb->local_i_key = p_cb->peer_i_key;
p_cb->local_r_key = p_cb->peer_r_key;
smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL);
}{...}
}{...} else {
reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...}
}{ ... }
#if (BLE_INCLUDED == TRUE)
/* ... */
void smp_proc_sl_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 key_type = p_data->key.key_type;
SMP_TRACE_DEBUG("%s\n", __func__);
if (key_type == SMP_KEY_TYPE_TK) {
smp_generate_srand_mrand_confirm(p_cb, NULL);
}{...} else if (key_type == SMP_KEY_TYPE_CFM) {
smp_set_state(SMP_STATE_WAIT_CONFIRM);
if (p_cb->flags & SMP_PAIR_FLAGS_CMD_CONFIRM) {
smp_sm_event(p_cb, SMP_CONFIRM_EVT, NULL);
}{...}
}{...}
}{ ... }
/* ... */
void smp_start_enc(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tBTM_STATUS cmd;
UINT8 reason = SMP_ENC_FAIL;
SMP_TRACE_DEBUG("%s\n", __func__);
if (p_data != NULL) {
cmd = btm_ble_start_encrypt(p_cb->pairing_bda, TRUE, p_data->key.p_data);
}{...} else {
cmd = btm_ble_start_encrypt(p_cb->pairing_bda, FALSE, NULL);
}{...}
if (cmd != BTM_CMD_STARTED && cmd != BTM_BUSY) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...}
}{ ... }
#endif/* ... */
/* ... */
void smp_proc_discard(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
if (!(p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)) {
smp_reset_control_value(p_cb);
}{...}
}{ ... }
/* ... */
void smp_enc_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 enc_enable = *(UINT8 *)p_data;
UINT8 reason = enc_enable ? SMP_SUCCESS : SMP_ENC_FAIL;
SMP_TRACE_DEBUG("%s\n", __func__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{ ... }
/* ... */
void smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 enc_enable = *(UINT8 *)p_data;
UINT8 reason = enc_enable ? SMP_SUCCESS : SMP_ENC_FAIL;
SMP_TRACE_DEBUG("%s rcvs enc_enable=%d i_keys=0x%x r_keys=0x%x "
"(i-initiator r-responder)\n",
__func__, enc_enable, p_cb->local_i_key, p_cb->local_r_key);
if (enc_enable == 1) {
if (p_cb->le_secure_connections_mode_is_used) {
p_cb->local_i_key |= SMP_SEC_KEY_TYPE_ENC;
p_cb->local_r_key |= SMP_SEC_KEY_TYPE_ENC;
if (!(p_cb->local_i_key & SMP_SEC_KEY_TYPE_LK) ||
!(p_cb->local_r_key & SMP_SEC_KEY_TYPE_LK)) {
p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK;
p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
}{...}
/* ... */
if (p_cb->role == HCI_ROLE_MASTER) {
p_cb->local_r_key &= (SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK);
}{...}
}{...} else {
p_cb->local_i_key &= ~SMP_SEC_KEY_TYPE_LK;
p_cb->local_r_key &= ~SMP_SEC_KEY_TYPE_LK;
}{...}
SMP_TRACE_DEBUG("%s rcvs upgrades: i_keys=0x%x r_keys=0x%x "
"(i-initiator r-responder)\n",
__func__, p_cb->local_i_key, p_cb->local_r_key);
if (
/* ... */
(p_cb->local_i_key || p_cb->local_r_key)) {
smp_sm_event(p_cb, SMP_BOND_REQ_EVT, NULL);
}{...} else {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...}
}{...} else if (enc_enable == 0) {
if (p_cb->flags & SMP_PAIR_FLAG_ENC_AFTER_PAIR) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...}
else if (p_cb->role == HCI_ROLE_MASTER) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...}
}{...}
}{ ... }
/* ... */
void smp_key_pick_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 key_to_dist = (p_cb->role == HCI_ROLE_SLAVE) ? p_cb->local_r_key : p_cb->local_i_key;
UINT8 i = 0;
SMP_TRACE_DEBUG("%s key_to_dist=0x%x\n", __func__, key_to_dist);
while (i < SMP_KEY_DIST_TYPE_MAX) {
SMP_TRACE_DEBUG("key to send = %02x, i = %d\n", key_to_dist, i);
if (key_to_dist & (1 << i) && smp_distribute_act[i] != NULL) {
SMP_TRACE_DEBUG("smp_distribute_act[%d]\n", i);
(* smp_distribute_act[i])(p_cb, p_data);
break;
}{...}
i ++;
}{...}
}{ ... }
#if (BLE_INCLUDED == TRUE)
/* ... */
void smp_key_distribution(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 reason = SMP_SUCCESS;
SMP_TRACE_DEBUG("\n%s role=%d (0-master) r_keys=0x%x i_keys=0x%x\n",
__func__, p_cb->role, p_cb->local_r_key, p_cb->local_i_key);
if (p_cb->role == HCI_ROLE_SLAVE ||
(!p_cb->local_r_key && p_cb->role == HCI_ROLE_MASTER)) {
smp_key_pick_key(p_cb, p_data);
}{...}
if (!p_cb->local_i_key && !p_cb->local_r_key) {
if (smp_get_state() == SMP_STATE_BOND_PENDING) {
if (p_cb->derive_lk) {
smp_derive_link_key_from_long_term_key(p_cb, NULL);
p_cb->derive_lk = FALSE;
}{...}
if (p_cb->total_tx_unacked == 0) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}{...} else {
p_cb->wait_for_authorization_complete = TRUE;
}{...}
}{...}
}{...}
}{ ... }
/* ... */
void smp_decide_association_model(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 failure = SMP_UNKNOWN_IO_CAP;
UINT8 int_evt = 0;
tSMP_KEY key;
tSMP_INT_DATA *p = NULL;
SMP_TRACE_DEBUG("%s Association Model = %d\n", __func__, p_cb->selected_association_model);
switch (p_cb->selected_association_model) {
case SMP_MODEL_ENCRYPTION_ONLY:
p_cb->sec_level = SMP_SEC_UNAUTHENTICATE;
SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_UNAUTHENTICATE) \n", p_cb->sec_level );
key.key_type = SMP_KEY_TYPE_TK;
key.p_data = p_cb->tk;
p = (tSMP_INT_DATA *)&key;
memset(p_cb->tk, 0, BT_OCTET16_LEN);
int_evt = SMP_KEY_READY_EVT;
break;
...
case SMP_MODEL_PASSKEY:
p_cb->sec_level = SMP_SEC_AUTHENTICATED;
SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) \n", p_cb->sec_level );
p_cb->cb_evt = SMP_PASSKEY_REQ_EVT;
int_evt = SMP_TK_REQ_EVT;
break;
...
case SMP_MODEL_OOB:
SMP_TRACE_ERROR ("Association Model = SMP_MODEL_OOB\n");
p_cb->sec_level = SMP_SEC_AUTHENTICATED;
SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED) \n", p_cb->sec_level );
p_cb->cb_evt = SMP_OOB_REQ_EVT;
int_evt = SMP_TK_REQ_EVT;
break;
...
case SMP_MODEL_KEY_NOTIF:
p_cb->sec_level = SMP_SEC_AUTHENTICATED;
SMP_TRACE_DEBUG("Need to generate Passkey\n");
smp_generate_passkey(p_cb, NULL);
break;
...
case SMP_MODEL_SEC_CONN_JUSTWORKS:
case SMP_MODEL_SEC_CONN_NUM_COMP:
case SMP_MODEL_SEC_CONN_PASSKEY_ENT:
case SMP_MODEL_SEC_CONN_PASSKEY_DISP:
case SMP_MODEL_SEC_CONN_OOB:
int_evt = SMP_PUBL_KEY_EXCH_REQ_EVT;
break;
...
case SMP_MODEL_OUT_OF_RANGE:
SMP_TRACE_ERROR("Association Model = SMP_MODEL_OUT_OF_RANGE (failed)\n");
p = (tSMP_INT_DATA *)&failure;
int_evt = SMP_AUTH_CMPL_EVT;
break;
...
default:
SMP_TRACE_ERROR("Association Model = %d (SOMETHING IS WRONG WITH THE CODE)\n",
p_cb->selected_association_model);
p = (tSMP_INT_DATA *)&failure;
int_evt = SMP_AUTH_CMPL_EVT;...
}{...}
SMP_TRACE_EVENT ("sec_level=%d \n", p_cb->sec_level );
if (int_evt) {
smp_sm_event(p_cb, int_evt, p);
}{...}
}{ ... }
/* ... */
void smp_process_io_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
uint8_t reason = SMP_PAIR_AUTH_FAIL;
SMP_TRACE_DEBUG("%s\n", __func__);
if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) {
smp_set_state(SMP_STATE_SEC_REQ_PENDING);
smp_send_cmd(SMP_OPCODE_SEC_REQ, p_cb);
}{...} else {
p_cb->selected_association_model = smp_select_association_model(p_cb);
if (p_cb->secure_connections_only_mode_required &&
(!(p_cb->le_secure_connections_mode_is_used) ||
(p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS))) {
SMP_TRACE_ERROR ("Slave requires secure connection only mode \
but it can't be provided -> Slave fails pairing\n");
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
uint16_t auth = smp_get_auth_mode(p_cb->selected_association_model);
if(p_cb->peer_auth_req & p_cb->loc_auth_req & SMP_AUTH_GEN_BOND) {
auth |= SMP_AUTH_GEN_BOND;
}{...}
p_cb->auth_mode = auth;
if (p_cb->accept_specified_sec_auth) {
if ((auth & p_cb->origin_loc_auth_req) != p_cb->origin_loc_auth_req ) {
SMP_TRACE_ERROR("pairing failed - slave requires auth is 0x%x but peer auth is 0x%x local auth is 0x%x",
p_cb->origin_loc_auth_req, p_cb->peer_auth_req, p_cb->loc_auth_req);
if (BTM_IsAclConnectionUp(p_cb->pairing_bda, BT_TRANSPORT_LE)) {
btm_remove_acl (p_cb->pairing_bda, BT_TRANSPORT_LE);
}{...}
reason = SMP_PAIR_AUTH_FAIL;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
}{...}
if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB && p_cb->loc_oob_flag == SMP_OOB_PRESENT) {
if (smp_request_oob_data(p_cb)) {
return;
}{...}
}{...}
smp_send_pair_rsp(p_cb, NULL);
}{...}
}{ ... }
#endif/* ... */
/* ... */
void smp_br_process_slave_keys_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
smp_br_send_pair_response(p_cb, NULL);
}{ ... }
/* ... */
void smp_br_send_pair_response(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
p_cb->local_i_key &= p_cb->peer_i_key;
p_cb->local_r_key &= p_cb->peer_r_key;
smp_send_cmd (SMP_OPCODE_PAIRING_RSP, p_cb);
}{ ... }
/* ... */
void smp_pairing_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
if (p_cb->total_tx_unacked == 0) {
smp_proc_pairing_cmpl(p_cb);
}{...}
}{ ... }
/* ... */
void smp_pair_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
p_cb->status = SMP_CONN_TOUT;
smp_proc_pairing_cmpl(p_cb);
}{ ... }
/* ... */
void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) {
SMP_TRACE_DEBUG("Pairing terminated at IDLE state.\n");
p_cb->status = SMP_FAIL;
smp_proc_pairing_cmpl(p_cb);
}{...}
}{ ... }
#if (BLE_INCLUDED == TRUE)
/* ... */
void smp_fast_conn_param(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
if(p_cb->role == BTM_ROLE_MASTER) {
#if (BT_MULTI_CONNECTION_ENBALE == FALSE)
L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, FALSE);
#endif
}{...} else {
#if (SMP_SLAVE_CON_PARAMS_UPD_ENABLE == TRUE)
tBTM_SEC_DEV_REC *p_rec = btm_find_dev (p_cb->pairing_bda);
if(p_rec && p_rec->ble.skip_update_conn_param) {
return;
}{...}
/* ... */
#if (BT_MULTI_CONNECTION_ENBALE == FALSE)
L2CA_EnableUpdateBleConnParams(p_cb->pairing_bda, FALSE);
#endif/* ... */
#endif
}{...}
}{ ... }
/* ... */
void smp_both_have_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
smp_compute_dhkey(p_cb);
if (p_cb->role == HCI_ROLE_SLAVE) {
smp_send_pair_public_key(p_cb, NULL);
}{...}
smp_sm_event(p_cb, SMP_SC_DHKEY_CMPLT_EVT, NULL);
}{ ... }
/* ... */
void smp_start_secure_connection_phase1(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) {
p_cb->sec_level = SMP_SEC_UNAUTHENTICATE;
SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_UNAUTHENTICATE)\n ", p_cb->sec_level );
}{...} else {
p_cb->sec_level = SMP_SEC_AUTHENTICATED;
SMP_TRACE_EVENT ("p_cb->sec_level =%d (SMP_SEC_AUTHENTICATED)\n ", p_cb->sec_level );
}{...}
switch (p_cb->selected_association_model) {
case SMP_MODEL_SEC_CONN_JUSTWORKS:
case SMP_MODEL_SEC_CONN_NUM_COMP:
memset(p_cb->local_random, 0, BT_OCTET16_LEN);
smp_start_nonce_generation(p_cb);
break;...
case SMP_MODEL_SEC_CONN_PASSKEY_ENT:
p_cb->cb_evt = SMP_PASSKEY_REQ_EVT;
smp_sm_event(p_cb, SMP_TK_REQ_EVT, NULL);
break;...
case SMP_MODEL_SEC_CONN_PASSKEY_DISP:
SMP_TRACE_DEBUG("Need to generate SC Passkey\n");
smp_generate_passkey(p_cb, NULL);
break;...
case SMP_MODEL_SEC_CONN_OOB:
smp_process_secure_connection_oob_data(p_cb, NULL);
break;...
default:
SMP_TRACE_ERROR ("Association Model = %d is not used in LE SC\n",
p_cb->selected_association_model);
break;...
}{...}
}{ ... }
/* ... */
void smp_process_local_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
switch (p_cb->selected_association_model) {
case SMP_MODEL_SEC_CONN_JUSTWORKS:
case SMP_MODEL_SEC_CONN_NUM_COMP:
if (p_cb->role == HCI_ROLE_SLAVE) {
smp_calculate_local_commitment(p_cb);
smp_send_commitment(p_cb, NULL);
smp_set_state(SMP_STATE_WAIT_NONCE);
}{...} else {
if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) {
SMP_TRACE_DEBUG("master in assoc mode = %d \
already rcvd slave commitment - race condition\n",
p_cb->selected_association_model);
p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM;
smp_send_rand(p_cb, NULL);
smp_set_state(SMP_STATE_WAIT_NONCE);
}{...}
}{...}
break;...
case SMP_MODEL_SEC_CONN_PASSKEY_ENT:
case SMP_MODEL_SEC_CONN_PASSKEY_DISP:
smp_calculate_local_commitment(p_cb);
if (p_cb->role == HCI_ROLE_MASTER) {
smp_send_commitment(p_cb, NULL);
}{...} else {
if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_COMM) {
smp_send_commitment(p_cb, NULL);
smp_set_state(SMP_STATE_WAIT_NONCE);
}{...}
}{...}
break;...
case SMP_MODEL_SEC_CONN_OOB:
if (p_cb->role == HCI_ROLE_MASTER) {
smp_send_rand(p_cb, NULL);
}{...}
smp_set_state(SMP_STATE_WAIT_NONCE);
break;...
default:
SMP_TRACE_ERROR ("Association Model = %d is not used in LE SC\n",
p_cb->selected_association_model);
break;...
}{...}
}{ ... }
/* ... */
void smp_process_peer_nonce(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 reason;
SMP_TRACE_DEBUG("%s start \n", __func__);
switch (p_cb->selected_association_model) {
case SMP_MODEL_SEC_CONN_JUSTWORKS:
case SMP_MODEL_SEC_CONN_NUM_COMP:
if (p_cb->role == HCI_ROLE_MASTER) {
if (!smp_check_commitment(p_cb)) {
reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
break;
}{...}
}{...} else {
smp_send_rand(p_cb, NULL);
}{...}
if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_JUSTWORKS) {
smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL);
}{...} else {
smp_set_state(SMP_STATE_WAIT_NONCE);
smp_sm_event(p_cb, SMP_SC_CALC_NC_EVT, NULL);
}{...}
break;...
case SMP_MODEL_SEC_CONN_PASSKEY_ENT:
case SMP_MODEL_SEC_CONN_PASSKEY_DISP:
if (!smp_check_commitment(p_cb)) {
reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
break;
}{...}
if (p_cb->role == HCI_ROLE_SLAVE) {
smp_send_rand(p_cb, NULL);
}{...}
if (++p_cb->round < 20) {
smp_set_state(SMP_STATE_SEC_CONN_PHS1_START);
p_cb->flags &= ~SMP_PAIR_FLAG_HAVE_PEER_COMM;
smp_start_nonce_generation(p_cb);
break;
}{...}
smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL);
break;...
case SMP_MODEL_SEC_CONN_OOB:
if (p_cb->role == HCI_ROLE_SLAVE) {
smp_send_rand(p_cb, NULL);
}{...}
smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL);
break;...
default:
SMP_TRACE_ERROR ("Association Model = %d is not used in LE SC\n",
p_cb->selected_association_model);
break;...
}{...}
SMP_TRACE_DEBUG("%s end\n ", __FUNCTION__);
}{ ... }
#endif/* ... */
/* ... */
void smp_match_dhkey_checks(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 reason = SMP_DHKEY_CHK_FAIL;
SMP_TRACE_DEBUG("%s\n", __func__);
if (memcmp(p_data->key.p_data, p_cb->remote_dhkey_check, BT_OCTET16_LEN)) {
SMP_TRACE_WARNING ("dhkey checks do no match\n");
p_cb->failure = reason;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
SMP_TRACE_EVENT ("dhkey checks match\n");
if (p_cb->peer_enc_size < p_cb->loc_enc_size) {
p_cb->loc_enc_size = p_cb->peer_enc_size;
}{...}
if (p_cb->role == HCI_ROLE_SLAVE) {
smp_sm_event(p_cb, SMP_PAIR_DHKEY_CHCK_EVT, NULL);
}{...} else {
p_cb->local_i_key = p_cb->peer_i_key;
p_cb->local_r_key = p_cb->peer_r_key;
smp_sm_event(p_cb, SMP_ENC_REQ_EVT, NULL);
}{...}
}{ ... }
/* ... */
void smp_move_to_secure_connections_phase2(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
smp_sm_event(p_cb, SMP_SC_PHASE1_CMPLT_EVT, NULL);
}{ ... }
/* ... */
void smp_phase_2_dhkey_checks_are_present(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
if (p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK) {
smp_sm_event(p_cb, SMP_SC_2_DHCK_CHKS_PRES_EVT, NULL);
}{...}
}{ ... }
/* ... */
void smp_wait_for_both_public_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
if ((p_cb->flags & SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY) &&
(p_cb->flags & SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY)) {
if ((p_cb->role == HCI_ROLE_SLAVE) &&
((p_cb->req_oob_type == SMP_OOB_LOCAL) || (p_cb->req_oob_type == SMP_OOB_BOTH))) {
smp_set_state(SMP_STATE_PUBLIC_KEY_EXCH);
}{...}
smp_sm_event(p_cb, SMP_BOTH_PUBL_KEYS_RCVD_EVT, NULL);
}{...}
}{ ... }
#if (BLE_INCLUDED == TRUE)
/* ... */
void smp_start_passkey_verification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 *p = NULL;
SMP_TRACE_DEBUG("%s\n", __func__);
p = p_cb->local_random;
UINT32_TO_STREAM(p, p_data->passkey);
p = p_cb->peer_random;
UINT32_TO_STREAM(p, p_data->passkey);
p_cb->round = 0;
smp_start_nonce_generation(p_cb);
}{ ... }
/* ... */
void smp_process_secure_connection_oob_data(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
tSMP_SC_OOB_DATA *p_sc_oob_data = &p_cb->sc_oob_data;
if (p_sc_oob_data->loc_oob_data.present) {
memcpy(p_cb->local_random, p_sc_oob_data->loc_oob_data.randomizer,
sizeof(p_cb->local_random));
}{...} else {
SMP_TRACE_EVENT ("local OOB randomizer is absent\n");
memset(p_cb->local_random, 0, sizeof (p_cb->local_random));
}{...}
if (!p_sc_oob_data->peer_oob_data.present) {
SMP_TRACE_EVENT ("peer OOB data is absent\n");
memset(p_cb->peer_random, 0, sizeof (p_cb->peer_random));
}{...} else {
memcpy(p_cb->peer_random, p_sc_oob_data->peer_oob_data.randomizer,
sizeof(p_cb->peer_random));
memcpy(p_cb->remote_commitment, p_sc_oob_data->peer_oob_data.commitment,
sizeof(p_cb->remote_commitment));
UINT8 reason = SMP_CONFIRM_VALUE_ERR;
if (!smp_check_commitment(p_cb)) {
p_cb->failure = reason;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
return;
}{...}
if (p_cb->peer_oob_flag != SMP_OOB_PRESENT) {
SMP_TRACE_EVENT ("peer didn't receive local OOB data, set local randomizer to 0\n");
memset(p_cb->local_random, 0, sizeof (p_cb->local_random));
}{...}
}{...}
print128(p_cb->local_random, (const UINT8 *)"local OOB randomizer");
print128(p_cb->peer_random, (const UINT8 *)"peer OOB randomizer");
smp_start_nonce_generation(p_cb);
}{ ... }
/* ... */
void smp_set_local_oob_keys(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
memcpy(p_cb->sc_oob_data.loc_oob_data.private_key_used, p_cb->private_key,
BT_OCTET32_LEN);
p_cb->sc_oob_data.loc_oob_data.publ_key_used = p_cb->loc_publ_key;
smp_start_nonce_generation(p_cb);
}{ ... }
/* ... */
void smp_set_local_oob_random_commitment(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
memcpy(p_cb->sc_oob_data.loc_oob_data.randomizer, p_cb->rand,
BT_OCTET16_LEN);
smp_calculate_f4(p_cb->sc_oob_data.loc_oob_data.publ_key_used.x,
p_cb->sc_oob_data.loc_oob_data.publ_key_used.x,
p_cb->sc_oob_data.loc_oob_data.randomizer, 0,
p_cb->sc_oob_data.loc_oob_data.commitment);
p_cb->sc_oob_data.loc_oob_data.present = true;
#if SMP_DEBUG == TRUE
UINT8 *p_print = NULL;
SMP_TRACE_DEBUG("local SC OOB data set:\n");
p_print = (UINT8 *) &p_cb->sc_oob_data.loc_oob_data.addr_sent_to;
smp_debug_print_nbyte_little_endian (p_print, (const UINT8 *)"addr_sent_to",
sizeof(tBLE_BD_ADDR));
p_print = (UINT8 *) &p_cb->sc_oob_data.loc_oob_data.private_key_used;
smp_debug_print_nbyte_little_endian (p_print, (const UINT8 *)"private_key_used",
BT_OCTET32_LEN);
p_print = (UINT8 *) &p_cb->sc_oob_data.loc_oob_data.publ_key_used.x;
smp_debug_print_nbyte_little_endian (p_print, (const UINT8 *)"publ_key_used.x",
BT_OCTET32_LEN);
p_print = (UINT8 *) &p_cb->sc_oob_data.loc_oob_data.publ_key_used.y;
smp_debug_print_nbyte_little_endian (p_print, (const UINT8 *)"publ_key_used.y",
BT_OCTET32_LEN);
p_print = (UINT8 *) &p_cb->sc_oob_data.loc_oob_data.randomizer;
smp_debug_print_nbyte_little_endian (p_print, (const UINT8 *)"randomizer",
BT_OCTET16_LEN);
p_print = (UINT8 *) &p_cb->sc_oob_data.loc_oob_data.commitment;
smp_debug_print_nbyte_little_endian (p_print, (const UINT8 *) "commitment",
BT_OCTET16_LEN);
SMP_TRACE_DEBUG("");/* ... */
#endif
p_cb->cb_evt = SMP_SC_LOC_OOB_DATA_UP_EVT;
smp_send_app_cback(p_cb, NULL);
smp_save_local_oob_data(p_cb);
smp_cb_cleanup(p_cb);
}{ ... }
/* ... */
void smp_link_encrypted(BD_ADDR bda, UINT8 encr_enable)
{
tSMP_CB *p_cb = &smp_cb;
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda);
SMP_TRACE_DEBUG("%s encr_enable=%d\n", __func__, encr_enable);
if (memcmp(&smp_cb.pairing_bda[0], bda, BD_ADDR_LEN) == 0) {
/* ... */
if (p_cb->loc_enc_size != 0 && encr_enable) {
btm_ble_update_sec_key_size(bda, p_cb->loc_enc_size);
}{...}
smp_sm_event(&smp_cb, SMP_ENCRYPTED_EVT, &encr_enable);
}{...} else if (p_dev_rec && !p_dev_rec->role_master && !p_dev_rec->enc_init_by_we ){
/* ... */
memcpy(&smp_cb.pairing_bda[0], bda, BD_ADDR_LEN);
p_cb->state = SMP_STATE_ENCRYPTION_PENDING;
p_cb->role = HCI_ROLE_SLAVE;
p_dev_rec->enc_init_by_we = FALSE;
smp_sm_event(&smp_cb, SMP_ENCRYPTED_EVT, &encr_enable);
}{...} else if (p_dev_rec && p_dev_rec->role_master && p_dev_rec->enc_init_by_we){
memcpy(&smp_cb.pairing_bda[0], bda, BD_ADDR_LEN);
p_cb->state = SMP_STATE_ENCRYPTION_PENDING;
p_cb->role = HCI_ROLE_MASTER;
p_dev_rec->enc_init_by_we = FALSE;
smp_sm_event(&smp_cb, SMP_ENCRYPTED_EVT, &encr_enable);
}{...}
}{ ... }
/* ... */
BOOLEAN smp_proc_ltk_request(BD_ADDR bda)
{
SMP_TRACE_DEBUG("%s state = %d\n", __func__, smp_cb.state);
BOOLEAN match = FALSE;
if (!memcmp(bda, smp_cb.pairing_bda, BD_ADDR_LEN)) {
match = TRUE;
}{...} else {
BD_ADDR dummy_bda = {0};
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bda);
if (p_dev_rec != NULL &&
0 == memcmp(p_dev_rec->ble.pseudo_addr, smp_cb.pairing_bda, BD_ADDR_LEN) &&
0 != memcmp(p_dev_rec->ble.pseudo_addr, dummy_bda, BD_ADDR_LEN)) {
match = TRUE;
}{...}
}{...}
if (match && smp_cb.state == SMP_STATE_ENCRYPTION_PENDING) {
smp_sm_event(&smp_cb, SMP_ENC_REQ_EVT, NULL);
return TRUE;
}{...}
return FALSE;
}{ ... }
/* ... */
void smp_process_secure_connection_long_term_key(void)
{
tSMP_CB *p_cb = &smp_cb;
SMP_TRACE_DEBUG("%s\n", __func__);
smp_save_secure_connections_long_term_key(p_cb);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, FALSE);
smp_key_distribution(p_cb, NULL);
}{ ... }
/* ... */
void smp_set_derive_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG ("%s\n", __func__);
p_cb->derive_lk = TRUE;
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_LK, FALSE);
smp_key_distribution(p_cb, NULL);
}{ ... }
/* ... */
void smp_derive_link_key_from_long_term_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN;
SMP_TRACE_DEBUG("%s\n", __func__);
if (!smp_calculate_link_key_from_long_term_key(p_cb)) {
SMP_TRACE_ERROR("%s failed\n", __FUNCTION__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status);
return;
}{...}
}{ ... }
#endif/* ... */
#if (CLASSIC_BT_INCLUDED == TRUE)
/* ... */
void smp_br_process_link_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN;
SMP_TRACE_DEBUG("%s\n", __func__);
if (!smp_calculate_long_term_key_from_link_key(p_cb)) {
SMP_TRACE_ERROR ("%s failed\n", __FUNCTION__);
smp_sm_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status);
return;
}{...}
SMP_TRACE_DEBUG("%s: LTK derivation from LK successfully completed\n", __FUNCTION__);
smp_save_secure_connections_long_term_key(p_cb);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, FALSE);
smp_br_select_next_key(p_cb, NULL);
}{...}
/* ... */#endif
/* ... */
void smp_key_distribution_by_transport(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
if (p_cb->smp_over_br) {
#if (CLASSIC_BT_INCLUDED == TRUE)
smp_br_select_next_key(p_cb, NULL);
#endif
}{...} else {
#if (BLE_INCLUDED == TRUE)
smp_key_distribution(p_cb, NULL);
#endif
}{...}
}{ ... }
/* ... */
void smp_br_pairing_complete(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
if (p_cb->total_tx_unacked == 0) {
smp_proc_pairing_cmpl(p_cb);
}{...}
}{ ... }
/* ... */#endif