1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
/**************************************************************************/
/*!
@file HAPPairing.cpp
@author hathach (tinyusb.org)
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2018, Adafruit Industries (adafruit.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#include <bluefruit.h>
#include "HAPUuid.h"
#include "HAPPairing.h"
#include "Bluefruit_FileIO.h"
#include "crypto/crypto.h"
#define DEBUG_HAP_PAIRING 0
/* SRP design detail http://srp.stanford.edu/design.html
*/
// kTLV type for pairing
enum {
PAIRING_TYPE_METHOD = 0 , // 0
PAIRING_TYPE_IDENTIFIER , // 1
PAIRING_TYPE_SALT , // 2
PAIRING_TYPE_PUBLIC_KEY , // 3
PAIRING_TYPE_PROOF , // 4
PAIRING_TYPE_ENCRYPTED_DATA , // 5
PAIRING_TYPE_STATE , // 6
PAIRING_TYPE_ERROR , // 7
PAIRING_TYPE_RETRY_DELAY , // 8
PAIRING_TYPE_CERTIFICATE , // 9
PAIRING_TYPE_SIGNATURE , // 10
PAIRING_TYPE_PERMISSIONS , // 11
PAIRING_TYPE_FRAGMENT_DATA , // 12
PAIRING_TYPE_FRAGMENT_LAST , // 13
PAIRING_TYPE_SEPARATOR = 0xff
};
// kTLV value for pairing method
enum
{
PAIRING_METHOD_SETUP = 1,
PAIRING_METHOD_VERIFY,
PAIRING_METHOD_ADD,
PAIRING_METHOD_REMOVE,
PAIRING_METHOD_LIST
};
// kTLV value for pairing error
enum
{
PAIRING_ERROR_UNKNOWN = 1,
PAIRING_ERROR_AUTHENTICATION,
PAIRING_ERROR_BACKOFF,
PAIRING_ERROR_MAX_PEERS,
PAIRING_ERROR_MAX_TRIES,
PAIRING_ERROR_UNAVAILABLE,
PAIRING_ERROR_BUSY
};
#if CFG_DEBUG >= 2
static const char* pairing_method_str[] =
{
"", "Pair Setup", "Pair Verify", "Add Pairing", "Remove Pairing", "List Pairings"
};
static const char* pairing_type_str[] =
{
"Method", "Identifier", "Salt", "Public Key", "Proof",
"Encrypted Data", "State", "Error", "Retry Delay", "Certificate",
"Signature", "Permissions", "Fragment Data", "Fragment Last",
};
#endif
void _pair_setup_write_cb (uint16_t conn_hdl, HAPCharacteristic* chr, HAPRequest_t const* hap_req);
void _pair_verify_write_cb (uint16_t conn_hdl, HAPCharacteristic* chr, HAPRequest_t const* hap_req);
// TODO add connection handle parameter
void gatt_reply_now(void)
{
ble_gatts_rw_authorize_reply_params_t reply =
{
.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE,
.params = {
.write = {
.gatt_status = BLE_GATT_STATUS_SUCCESS,
.update = 1,
}
}
};
VERIFY_STATUS( sd_ble_gatts_rw_authorize_reply(Bluefruit.connHandle(), &reply), );
}
HAPPairing::HAPPairing(void)
: HAPService(HAP_UUID_SVC_PAIRING),
_setup (HAP_UUID_CHR_PAIR_SETUP , BLE_GATT_CPF_FORMAT_STRUCT),
_verify (HAP_UUID_CHR_PAIR_VERIFY , BLE_GATT_CPF_FORMAT_STRUCT),
_features (HAP_UUID_SVC_PAIR_FEATURE , BLE_GATT_CPF_FORMAT_UINT8 ),
_pairing (HAP_UUID_SVC_PAIR_PAIRING , BLE_GATT_CPF_FORMAT_STRUCT)
{
varclr(_pair_id);
}
err_t HAPPairing::begin(void)
{
VERIFY_STATUS( HAPService::begin() ); // Invoke base class begin()
_setup.setHapProperties(HAP_CHR_PROPS_READ | HAP_CHR_PROPS_WRITE);
_setup.setHapWriteCallback(_pair_setup_write_cb);
_setup.setMaxLen(200); // FIXME change later
VERIFY_STATUS( _setup.begin() );
_verify.setHapProperties(HAP_CHR_PROPS_READ | HAP_CHR_PROPS_WRITE);
_verify.setHapWriteCallback(_pair_verify_write_cb);
_verify.setMaxLen(200); // FIXME change later
VERIFY_STATUS( _verify.begin() );
_features.setHapProperties(HAP_CHR_PROPS_READ);
VERIFY_STATUS( _features.begin() );
// Must be 0x00, 0x01 (support HAP pairing) is for MFi license, iOS will reject pairing attempt without MFi
_features.writeHapValue( (uint32_t) 0x00);
_pairing.setHapProperties(HAP_CHR_PROPS_SECURE_READ | HAP_CHR_PROPS_SECURE_WRITE);
VERIFY_STATUS( _pairing.begin() );
// Make PairID based on MAC address
uint8_t mac[6];
Bluefruit.Gap.getAddr(mac);
setDeviceID(mac);
// Init cryptography
if ( !InternalFS.exists("/adafruit/homekit") ) InternalFS.mkdir("/adafruit/homekit");
crypto_init();
return ERROR_NONE;
}
void HAPPairing::setDeviceID(uint8_t dev_id[6])
{
char str[sizeof(_pair_id) + 1];
sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", dev_id[0], dev_id[1], dev_id[2], dev_id[3], dev_id[4], dev_id[5]);
memcpy(_pair_id, str, sizeof(_pair_id));
}
void HAPPairing::createSrpResponse(uint16_t conn_hdl, uint8_t status, TLV8_t ktlv[], uint8_t count)
{
uint16_t srplen = tlv8_encode_calculate_len(ktlv, count);
uint8_t* srpbuf = (uint8_t*) rtos_malloc(srplen);
VERIFY( srpbuf != NULL, );
if( srplen == tlv8_encode_n(srpbuf, srplen, ktlv, count) )
{
#if DEBUG_HAP_PAIRING
LOG_LV2_BUFFER("srpbuf", srpbuf, srplen);
#endif
TLV8_t tlv = { .type = HAP_PARAM_VALUE, .len = srplen, .value = srpbuf };
_setup.createHapResponse(conn_hdl, status, &tlv, 1);
}
rtos_free(srpbuf);
}
/*------------------------------------------------------------------*/
/* PAIR SETUP
*------------------------------------------------------------------*/
void HAPPairing::pair_setup_m1(uint16_t conn_hdl, HAPRequest_t const* hap_req)
{
// if paired return PAIRING_ERROR_UNAVAILABLE
// tries more than 100 time return PAIRING_ERROR_MAX_TRIES
// pairing with other iOS return PAIRING_ERROR_BUSY
// step 4
srp_start();
// step 5 : username (I) = "Pair-Setup"
// step 6 : 16 bytes salt already created in srp_init()
// step 7,8 : password (p = setup code) done in srp_init()
// step 9 : public key (B) done in srp_init()
uint8_t mstate = 2;
TLV8_t tlv_para[] =
{
{ .type = PAIRING_TYPE_STATE , .len = 1 , .value = &mstate },
{ .type = PAIRING_TYPE_PUBLIC_KEY , .len = 384, .value = srp_getB() },
{ .type = PAIRING_TYPE_SALT , .len = 16 , .value = srp_getSalt() },
};
#if DEBUG_HAP_PAIRING
LOG_LV2_BUFFER("SRP State" , tlv_para[0].value, tlv_para[0].len);
LOG_LV2_BUFFER("SRP Pub Key", tlv_para[1].value, tlv_para[1].len);
LOG_LV2_BUFFER("SRP Salt" , tlv_para[2].value, tlv_para[2].len);
#endif
createSrpResponse(conn_hdl, HAP_STATUS_SUCCESS, tlv_para, arrcount(tlv_para));
}
void HAPPairing::pair_setup_m3(uint16_t conn_hdl, HAPRequest_t const* hap_req, TLV8_t pubkey, TLV8_t proof)
{
uint8_t mstate = 4;
uint8_t pair_error = PAIRING_ERROR_AUTHENTICATION;
TLV8_t tlv_para[2] =
{
{ .type = PAIRING_TYPE_STATE, .len = 1, .value = &mstate },
{ 0 }
};
#if DEBUG_HAP_PAIRING
LOG_LV2_BUFFER("SRP State", tlv_para[0].value, tlv_para[0].len);
#endif
// Set iOS public key
srp_setA( (uint8_t*) pubkey.value, pubkey.len, gatt_reply_now);
// Check proof
if ( srp_checkM1( (uint8_t*) proof.value, proof.len) )
{
tlv_para[1].type = PAIRING_TYPE_PROOF;
tlv_para[1].len = 64;
tlv_para[1].value = srp_getM2();
#if DEBUG_HAP_PAIRING
LOG_LV2_BUFFER("SRP Proof", tlv_para[1].value, tlv_para[1].len);
#endif
}else
{
tlv_para[1].type = PAIRING_TYPE_ERROR;
tlv_para[1].len = 1;
tlv_para[1].value = &pair_error;
#if DEBUG_HAP_PAIRING
LOG_LV2_BUFFER("SRP Error", tlv_para[1].value, tlv_para[1].len);
#endif
}
createSrpResponse(conn_hdl, HAP_STATUS_SUCCESS, tlv_para, arrcount(tlv_para));
}
void HAPPairing::pair_setup_m5(uint16_t conn_hdl, HAPRequest_t const* hap_req, TLV8_t encrypted)
{
uint8_t const pair_error = PAIRING_ERROR_AUTHENTICATION;
uint8_t const mstate = 6;
TLV8_t tlv_para[2] =
{
{ .type = PAIRING_TYPE_STATE, .len = 1, .value = &mstate },
{ 0 }
};
bool failed = false;
/*------------------------------------------------------------------*/
/* M5 Verification
*------------------------------------------------------------------*/
uint8_t session_key[64];
// Step 0: Create Session Key
crypto_hkdf(session_key, (uint8_t*) "Pair-Setup-Encrypt-Salt", 23, (uint8_t*) "Pair-Setup-Encrypt-Info\001", 24, srp_getK(), 64);
// Step 1 + 2: Verify Auth Tag and Decrypt using ChaCha20-Poly1305
if (crypto_verifyAndDecrypt(session_key, (uint8_t*) "PS-Msg05", (uint8_t*)encrypted.value, encrypted.len - 16, (uint8_t*) encrypted.value, ((uint8_t*) encrypted.value) + encrypted.len - 16))
{
uint16_t blength = encrypted.len - 16;
uint8_t const* buf = (uint8_t const*) encrypted.value;
uint8_t* client = NULL;
uint8_t* signature = NULL;
uint8_t* ltpk = NULL;
// Parse iOS's ID, Public Key (ED25519) and Signature
while(blength)
{
TLV8_t tlv = tlv8_decode_next(&buf, &blength);
LOG_LV2("M5", "type = %s", tlv.type == PAIRING_TYPE_SEPARATOR ? "Separator" : pairing_type_str[tlv.type]);
LOG_LV2_BUFFER(NULL, tlv.value, tlv.len);
switch(tlv.type)
{
case PAIRING_TYPE_IDENTIFIER:
VERIFY(tlv.len == 36, );
client = (uint8_t*) tlv.value;
break;
case PAIRING_TYPE_PUBLIC_KEY:
VERIFY(tlv.len == 32, );
ltpk = (uint8_t*) tlv.value;
break;
case PAIRING_TYPE_SIGNATURE:
VERIFY(tlv.len == 64, );
signature = (uint8_t*) tlv.value;
break;
default:
failed = true;
break;
}
// There is no value > 255, there is no need to clean up. Put here for reference only
// tlv8_decode_cleanup(tlv);
}
if (client && signature && ltpk)
{
// iOSDeviceInfo = iOSDeviceX + iOSDevicePairingID, iOSDeviceLTPK
uint8_t message[64 + 32 + 36 + 32];
memcpy(message, signature, 64);
// Step 3: Derive iOSDeviceX
crypto_hkdf(message + 64, (uint8_t*) "Pair-Setup-Controller-Sign-Salt", 31, (uint8_t*) "Pair-Setup-Controller-Sign-Info\001", 32, srp_getK(), 64);
// Step 4: Construct iOSDeviceInfo
memcpy(message + 64 + 32, client, 36);
memcpy(message + 64 + 32 + 36, ltpk, 32);
uint8_t result[sizeof(message)];
uint64_t rlen = 0;
// Step 5: Verify iOSDeviceInfo with ED25519
if (crypto_sign_open(result, &rlen, message, sizeof(message), ltpk) < 0)
{
failed = true;
}
else
{
// Step 6: save PairingID and LTPK
memcpy(crypto_keys.client.ltpk, ltpk, sizeof(crypto_keys.client.ltpk));
memcpy(crypto_keys.client.name, client, 36);
crypto_scheduleStoreKeys();
// If failed to save ---> MaxPeers error
}
}
}
else
{
// Error
failed = true;
}
if (failed)
{
tlv_para[1].type = PAIRING_TYPE_ERROR;
tlv_para[1].len = 1;
tlv_para[1].value = &pair_error;
createSrpResponse(conn_hdl, HAP_STATUS_SUCCESS, tlv_para, arrcount(tlv_para));
return;
}
/*------------------------------------------------------------------*/
/* M6 Response Generation
*------------------------------------------------------------------*/
uint8_t smessage[64 + 32 + sizeof(_pair_id) + 32];
// Step 2: derive AccessoryX using HKDF_SHA512
crypto_hkdf(smessage + 64, (uint8_t*) "Pair-Setup-Accessory-Sign-Salt", 30, (uint8_t*) "Pair-Setup-Accessory-Sign-Info\001", 31, srp_getK(), 64);
// Step 3: Concat AccessoryX + PairingID + AccessoryLTPK
memcpy(smessage + 64 + 32, _pair_id, sizeof(_pair_id));
memcpy(smessage + 64 + 32 + sizeof(_pair_id), crypto_keys.sign.pub, sizeof(crypto_keys.sign.pub));
// Step 4: Generate AccessorySignature with Ed25519
uint64_t slen = 0;
crypto_sign(smessage, &slen, smessage + 64, sizeof(smessage) - 64, crypto_keys.sign.secret);
// Step 5: Construct sub-tlv
TLV8_t ktlv[] =
{
{ .type = PAIRING_TYPE_IDENTIFIER, .len = sizeof(_pair_id), .value = _pair_id },
{ .type = PAIRING_TYPE_PUBLIC_KEY, .len = 32, .value = crypto_keys.sign.pub },
{ .type = PAIRING_TYPE_SIGNATURE , .len = 64, .value = smessage }
};
uint16_t const lbuffer = tlv8_encode_calculate_len(ktlv, arrcount(ktlv));
uint8_t* buffer = (uint8_t*) rtos_malloc(lbuffer + 16); // Additional 16 byte for Auth Tag
VERIFY( buffer != NULL, );
tlv8_encode_n(buffer, lbuffer, ktlv, arrcount(ktlv));
// Step 6: Encrypt above sub-tlv and generate 16-byte auth tag.
crypto_encryptAndSeal(session_key, (uint8_t*) "PS-Msg06", buffer, lbuffer, buffer, buffer + lbuffer);
tlv_para[1].type = PAIRING_TYPE_ENCRYPTED_DATA;
tlv_para[1].len = lbuffer+16;
tlv_para[1].value = buffer;
createSrpResponse(conn_hdl, HAP_STATUS_SUCCESS, tlv_para, arrcount(tlv_para));
rtos_free(buffer);
}
void _pair_setup_write_cb (uint16_t conn_hdl, HAPCharacteristic* chr, HAPRequest_t const* hap_req)
{
uint16_t body_len = hap_req->body_len;
uint8_t const* body_data = hap_req->body_data;
// Parse TLV data
while (body_len)
{
TLV8_t tlv = tlv8_decode_next(&body_data, &body_len);
LOG_LV2_BUFFER("Decoded HAP", tlv.value, tlv.len);
// ignore HAP_PARAM_RETURN_RESP, it should always been 1 for pair setup sequence
if (HAP_PARAM_VALUE == tlv.type)
{
uint8_t mstate = 0;
// M1 parameters
uint8_t method = 0;
// M3 parameters
TLV8_t ipubkey = { 0 }; // (A ) 384 bytes
TLV8_t iproof = { 0 }; // (M1) 64 bytes
TLV8_t iencrypted = { 0 }; // Encrypted data
/*------------- Parse sub TLV (kTLV) data -------------*/
uint8_t const* param_val = (uint8_t const*) tlv.value;
uint16_t param_len = tlv.len;
while(param_len)
{
TLV8_t ktlv = tlv8_decode_next(¶m_val, ¶m_len);
LOG_LV2("Pair-Setup", "type = %s", ktlv.type == PAIRING_TYPE_SEPARATOR ? "Separator" : pairing_type_str[ktlv.type]);
LOG_LV2_BUFFER(NULL, ktlv.value, ktlv.len);
switch (ktlv.type)
{
case PAIRING_TYPE_METHOD:
memcpy(&method, ktlv.value, 1);
LOG_LV2("HAP", "Method %s", pairing_method_str[method]);
break;
// TODO multiple pairing support
case PAIRING_TYPE_STATE:
memcpy(&mstate, ktlv.value, 1);
LOG_LV2("HAP", "State = M%d", mstate);
break;
case PAIRING_TYPE_PUBLIC_KEY:
ipubkey = ktlv;
break;
case PAIRING_TYPE_PROOF:
iproof = ktlv;
break;
case PAIRING_TYPE_ENCRYPTED_DATA:
iencrypted = ktlv;
break;
// ignore other type and clean up
default:
tlv8_decode_cleanup(ktlv);
break;
}
// Purposely skip tlv8_decode_cleanup() here, will call it later after processing
}
/*------------- Processing setup sequence -------------*/
HAPPairing& svc = (HAPPairing&) chr->parentService();
switch (mstate)
{
case 1:
svc.pair_setup_m1(conn_hdl, hap_req);
break;
case 3:
svc.pair_setup_m3(conn_hdl, hap_req, ipubkey, iproof);
tlv8_decode_cleanup(ipubkey);
tlv8_decode_cleanup(iproof);
break;
case 5:
svc.pair_setup_m5(conn_hdl, hap_req, iencrypted);
tlv8_decode_cleanup(iencrypted);
break;
default: break;
}
}
tlv8_decode_cleanup(tlv);
}
}
/*------------------------------------------------------------------*/
/* PAIR VERIFY
*------------------------------------------------------------------*/
void _pair_verify_write_cb (uint16_t conn_hdl, HAPCharacteristic* chr, HAPRequest_t const* hap_req)
{
uint16_t body_len = hap_req->body_len;
uint8_t const* body_data = hap_req->body_data;
// Parse TLV data
while (body_len)
{
TLV8_t tlv = tlv8_decode_next(&body_data, &body_len);
LOG_LV2_BUFFER("Decoded HAP", tlv.value, tlv.len);
// ignore HAP_PARAM_RETURN_RESP, it should always been 1 for pair setup sequence
if (HAP_PARAM_VALUE == tlv.type)
{
uint8_t mstate = 0;
TLV8_t tlvparam = { 0 };
/*------------- Parse sub TLV (kTLV) data -------------*/
uint8_t const* param_val = (uint8_t const*) tlv.value;
uint16_t param_len = tlv.len;
while(param_len)
{
TLV8_t ktlv = tlv8_decode_next(¶m_val, ¶m_len);
LOG_LV2("Pair-Verify", "type = %s", ktlv.type == PAIRING_TYPE_SEPARATOR ? "Separator" : pairing_type_str[ktlv.type]);
LOG_LV2_BUFFER(NULL, ktlv.value, ktlv.len);
switch (ktlv.type)
{
case PAIRING_TYPE_STATE:
memcpy(&mstate, ktlv.value, 1);
LOG_LV2("HAP", "State = M%d", mstate);
break;
case PAIRING_TYPE_PUBLIC_KEY:
tlvparam = ktlv;
break;
case PAIRING_TYPE_ENCRYPTED_DATA:
tlvparam = ktlv;
break;
// ignore other type and clean up
default:
tlv8_decode_cleanup(ktlv);
break;
}
// Purposely skip tlv8_decode_cleanup() here, will call it later after processing
}
/*------------- Processing VERIFY sequence -------------*/
HAPPairing& svc = (HAPPairing&) chr->parentService();
switch (mstate)
{
case 1:
svc.pair_verify_m1(conn_hdl, hap_req, tlvparam);
break;
case 3:
svc.pair_verify_m3(conn_hdl, hap_req, tlvparam);
break;
default: break;
}
tlv8_decode_cleanup(tlvparam);
}
tlv8_decode_cleanup(tlv);
}
}
void HAPPairing::pair_verify_m1(uint16_t conn_hdl, HAPRequest_t const* hap_req, TLV8_t pubkey)
{
}
void HAPPairing::pair_verify_m3(uint16_t conn_hdl, HAPRequest_t const* hap_req, TLV8_t encrypted)
{
}
|