@@ -360,10 +360,136 @@ ble_ll_cs_hci_wr_cached_rem_supp_cap(const uint8_t *cmdbuf, uint8_t cmdlen,
360
360
return BLE_ERR_SUCCESS ;
361
361
}
362
362
363
+ int
364
+ ble_ll_cs_rx_security_req (struct ble_ll_conn_sm * connsm , uint8_t * dptr ,
365
+ uint8_t * rspbuf )
366
+ {
367
+ uint8_t * iv = connsm -> cssm -> drbg_ctx .iv ;
368
+ uint8_t * in = connsm -> cssm -> drbg_ctx .in ;
369
+ uint8_t * pv = connsm -> cssm -> drbg_ctx .pv ;
370
+
371
+ if (!connsm -> flags .encrypted ) {
372
+ ble_ll_ctrl_rej_ext_ind_make (BLE_LL_CTRL_CS_SEC_REQ ,
373
+ BLE_ERR_INSUFFICIENT_SEC , rspbuf );
374
+ return BLE_LL_CTRL_REJECT_IND_EXT ;
375
+ }
376
+
377
+ /* Vectors concatenation is done in the follwing manner:
378
+ * CS_IV = CS_IV_P || CS_IV_C
379
+ * The CS_IV_C is concatenated with the CS_IV_P. The least significant
380
+ * octet of CS_IV_C becomes the least significant octet of CS_IV. The most
381
+ * significant octet of CS_IV_P becomes the most significant octet of CS_IV.
382
+ */
383
+
384
+ /* Save Central's vector */
385
+ memcpy (iv , dptr , 8 );
386
+ memcpy (in , dptr + 8 , 4 );
387
+ memcpy (pv , dptr + 12 , 8 );
388
+
389
+ /* Generate Peripheral's vector */
390
+ ble_ll_rand_data_get (iv + 8 , 8 );
391
+ ble_ll_rand_data_get (in + 4 , 4 );
392
+ ble_ll_rand_data_get (pv + 8 , 8 );
393
+
394
+ memcpy (rspbuf , iv + 8 , 8 );
395
+ memcpy (rspbuf + 8 , in + 4 , 4 );
396
+ memcpy (rspbuf + 12 , pv + 8 , 8 );
397
+
398
+ ble_ll_cs_drbg_init (& connsm -> cssm -> drbg_ctx );
399
+
400
+ return BLE_LL_CTRL_CS_SEC_RSP ;
401
+ }
402
+
403
+ static void
404
+ ble_ll_cs_ev_sec_enable_complete (struct ble_ll_conn_sm * connsm , uint8_t status )
405
+ {
406
+ struct ble_hci_ev_le_subev_cs_sec_enable_complete * ev ;
407
+ struct ble_hci_ev * hci_ev ;
408
+
409
+ if (ble_ll_hci_is_le_event_enabled (
410
+ BLE_HCI_LE_SUBEV_CS_SEC_ENABLE_COMPLETE )) {
411
+ hci_ev = ble_transport_alloc_evt (0 );
412
+ if (hci_ev ) {
413
+ hci_ev -> opcode = BLE_HCI_EVCODE_LE_META ;
414
+ hci_ev -> length = sizeof (* ev );
415
+ ev = (void * ) hci_ev -> data ;
416
+
417
+ ev -> subev_code = BLE_HCI_LE_SUBEV_CS_SEC_ENABLE_COMPLETE ;
418
+ ev -> status = status ;
419
+ ev -> conn_handle = htole16 (connsm -> conn_handle );
420
+
421
+ ble_ll_hci_event_send (hci_ev );
422
+ }
423
+ }
424
+ }
425
+
426
+ void
427
+ ble_ll_cs_rx_security_rsp (struct ble_ll_conn_sm * connsm , uint8_t * dptr )
428
+ {
429
+ int rc = 0 ;
430
+ struct ble_ll_cs_drbg_ctx * drbg_ctx = & connsm -> cssm -> drbg_ctx ;
431
+
432
+ if (!IS_PENDING_CTRL_PROC (connsm , BLE_LL_CTRL_PROC_CS_SEC_START )) {
433
+ /* Ignore */
434
+ return ;
435
+ }
436
+
437
+ /* Save Peripheral's vector */
438
+ memcpy (drbg_ctx -> iv + 8 , dptr , 8 );
439
+ memcpy (drbg_ctx -> in + 4 , dptr + 8 , 4 );
440
+ memcpy (drbg_ctx -> pv + 8 , dptr + 12 , 8 );
441
+
442
+ rc = ble_ll_cs_drbg_init (drbg_ctx );
443
+
444
+ /* Stop the control procedure and send an event to the host */
445
+ ble_ll_ctrl_proc_stop (connsm , BLE_LL_CTRL_PROC_CS_SEC_START );
446
+ ble_ll_cs_ev_sec_enable_complete (connsm , rc ? BLE_ERR_INV_LMP_LL_PARM :
447
+ BLE_ERR_SUCCESS );
448
+ }
449
+
450
+ void
451
+ ble_ll_cs_rx_security_req_rejected (struct ble_ll_conn_sm * connsm , uint8_t ble_error )
452
+ {
453
+ /* Stop the control procedure and send an event to the host */
454
+ ble_ll_ctrl_proc_stop (connsm , BLE_LL_CTRL_PROC_CS_SEC_START );
455
+ ble_ll_cs_ev_sec_enable_complete (connsm , ble_error );
456
+ }
457
+
458
+ void
459
+ ble_ll_cs_security_req_make (struct ble_ll_conn_sm * connsm , uint8_t * dptr )
460
+ {
461
+ uint8_t * iv = connsm -> cssm -> drbg_ctx .iv ;
462
+ uint8_t * in = connsm -> cssm -> drbg_ctx .in ;
463
+ uint8_t * pv = connsm -> cssm -> drbg_ctx .pv ;
464
+
465
+ /* Generate Central's vector */
466
+ ble_ll_rand_data_get (iv , 8 );
467
+ ble_ll_rand_data_get (in , 4 );
468
+ ble_ll_rand_data_get (pv , 8 );
469
+
470
+ memcpy (dptr , iv , 8 );
471
+ memcpy (dptr + 8 , in , 4 );
472
+ memcpy (dptr + 12 , pv , 8 );
473
+ }
474
+
363
475
int
364
476
ble_ll_cs_hci_sec_enable (const uint8_t * cmdbuf , uint8_t cmdlen )
365
477
{
366
- return BLE_ERR_UNSUPPORTED ;
478
+ const struct ble_hci_le_cs_sec_enable_cp * cmd = (const void * )cmdbuf ;
479
+ struct ble_ll_conn_sm * connsm ;
480
+
481
+ connsm = ble_ll_conn_find_by_handle (le16toh (cmd -> conn_handle ));
482
+ if (!connsm ) {
483
+ return BLE_ERR_UNK_CONN_ID ;
484
+ }
485
+
486
+ if (!connsm -> flags .encrypted ) {
487
+ return BLE_ERR_INSUFFICIENT_SEC ;
488
+ }
489
+
490
+ ble_ll_ctrl_proc_start (connsm , BLE_LL_CTRL_PROC_CS_SEC_START , NULL );
491
+
492
+ return BLE_ERR_SUCCESS ;
367
493
}
368
494
369
495
int
0 commit comments