@@ -172,8 +172,8 @@ ble_eatt_prepare_rx_sdu(struct ble_l2cap_chan *chan)
172
172
173
173
rc = ble_l2cap_recv_ready (chan , om );
174
174
if (rc ) {
175
- BLE_EATT_LOG_ERROR ("eatt: Failed to supply RX SDU conn_handle 0x%04x (status=%d)\n" ,
176
- chan -> conn_handle , rc );
175
+ BLE_EATT_LOG_ERROR ("eatt: Failed to supply RX SDU conn_handle"
176
+ "0x%04x (status=%d)\n" , chan -> conn_handle , rc );
177
177
os_mbuf_free_chain (om );
178
178
}
179
179
@@ -279,10 +279,6 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
279
279
case BLE_L2CAP_EVENT_COC_CONNECTED :
280
280
eatt = ble_eatt_find_by_conn_handle (event -> connect .conn_handle );
281
281
282
- BLE_EATT_LOG_DEBUG ("eatt: Connected event | conn_handle: %d | scid: %d | dcid: %d\n" ,
283
- event -> connect .conn_handle , event -> connect .chan -> scid ,
284
- event -> connect .chan -> dcid );
285
-
286
282
if (event -> connect .status == BLE_HS_ENOMEM && eatt -> collision_ctrl ) {
287
283
BLE_EATT_LOG_DEBUG ("eatt: Connection collision\n" );
288
284
@@ -296,7 +292,8 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
296
292
297
293
coll_delay = (rand_part % 5 ) + 2 * (desc .conn_latency + 1 ) * desc .conn_itvl ;
298
294
299
- os_callout_reset (& eatt -> collision_co , OS_TICKS_PER_SEC / 1000 * coll_delay );
295
+ os_callout_reset (& eatt -> collision_co ,
296
+ OS_TICKS_PER_SEC / 1000 * coll_delay );
300
297
301
298
return 0 ;
302
299
}
@@ -315,17 +312,22 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
315
312
316
313
/* Increase used channel number on connected event */
317
314
eatt -> used_channels ++ ;
318
- BLE_EATT_LOG_DEBUG ("eatt: Channels already used for this connection: %d\n" ,
319
- eatt -> used_channels );
315
+ BLE_EATT_LOG_DEBUG ("eatt: Conn event | conn_handle: %d"
316
+ "| scid: %d | dcid: %d | channels used: %d\n" ,
317
+ event -> connect .conn_handle , event -> connect .chan -> scid ,
318
+ event -> connect .chan -> dcid , eatt -> used_channels );
320
319
break ;
321
320
case BLE_L2CAP_EVENT_COC_DISCONNECTED :
322
- BLE_EATT_LOG_DEBUG ("eatt: Disconnected event | conn_handle: %d | scid: %d | dcid: %d\n" ,
323
- event -> accept .conn_handle , event -> accept .chan -> scid ,
324
- event -> accept .chan -> dcid );
321
+ BLE_EATT_LOG_DEBUG ("eatt: Disconnected event | conn_handle: %d"
322
+ "| scid: %d | dcid: %d\n" ,
323
+ event -> accept .conn_handle , event -> accept .chan -> scid ,
324
+ event -> accept .chan -> dcid );
325
325
326
326
eatt = ble_eatt_find_by_conn_handle (event -> disconnect .conn_handle );
327
327
if (!eatt ) {
328
- BLE_EATT_LOG_ERROR ("eatt: Disconnected event | No eatt found\n" );
328
+ BLE_EATT_LOG_ERROR ("eatt: Disconnected event | No EATT associated"
329
+ "with conn_handle: %d\n" ,
330
+ event -> disconnect .conn_handle );
329
331
return 0 ;
330
332
}
331
333
@@ -341,13 +343,16 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
341
343
break ;
342
344
case BLE_L2CAP_EVENT_COC_ACCEPT :
343
345
346
+
344
347
/* Lookup if EATT already exists for this connection */
345
348
eatt = ble_eatt_find_by_conn_handle (event -> accept .conn_handle );
346
349
if (!eatt ) {
347
350
eatt = ble_eatt_alloc ();
348
351
} else {
349
352
/* Check for free channels for this connection */
350
- free_channels = MYNEWT_VAL (BLE_EATT_CHAN_PER_CONN ) - eatt -> accept_chans ;
353
+ free_channels =
354
+ MYNEWT_VAL (BLE_EATT_CHAN_PER_CONN ) -
355
+ eatt -> accept_chans ;
351
356
352
357
if (free_channels == 0 ) {
353
358
BLE_EATT_LOG_ERROR ("eatt: Accept event | No free channel slots\n" );
@@ -360,7 +365,7 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
360
365
361
366
/* We do not increase number of used channels
362
367
* here - only on connected event & while initiating connection
363
- * Here we increase field for accept channels - yet to be connected.
368
+ * Only increase field for accept channels - yet to be connected.
364
369
*/
365
370
eatt -> accept_chans ++ ;
366
371
@@ -423,7 +428,8 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
423
428
return BLE_HS_EREJECT ;
424
429
}
425
430
426
- ble_eatt_att_rx_cb (event -> receive .conn_handle , eatt -> chan -> scid , & event -> receive .sdu_rx );
431
+ ble_eatt_att_rx_cb (event -> receive .conn_handle , eatt -> chan -> scid ,
432
+ & event -> receive .sdu_rx );
427
433
if (event -> receive .sdu_rx ) {
428
434
os_mbuf_free_chain (event -> receive .sdu_rx );
429
435
event -> receive .sdu_rx = NULL ;
@@ -460,15 +466,16 @@ ble_eatt_setup_cb(struct ble_npl_event *ev)
460
466
return ;
461
467
}
462
468
463
- BLE_EATT_LOG_DEBUG ("eatt: connecting eatt on conn_handle 0x%04x\n" , eatt -> conn_handle );
469
+ BLE_EATT_LOG_DEBUG ("eatt: connecting eatt on conn_handle 0x%04x\n" ,
470
+ eatt -> conn_handle );
464
471
465
472
rc = ble_l2cap_enhanced_connect (eatt -> conn_handle , BLE_EATT_PSM ,
466
473
MYNEWT_VAL (BLE_EATT_MTU ),
467
474
eatt -> chan_num , & om ,
468
475
ble_eatt_l2cap_event_fn , eatt );
469
476
if (rc ) {
470
- BLE_EATT_LOG_ERROR ("eatt: Failed to connect EATT on conn_handle 0x%04x (status=%d)\n" ,
471
- eatt -> conn_handle , rc );
477
+ BLE_EATT_LOG_ERROR ("eatt: Failed to connect EATT on conn_handle"
478
+ "0x%04x (status=%d)\n" , eatt -> conn_handle , rc );
472
479
os_mbuf_free_chain (om );
473
480
ble_eatt_free (eatt );
474
481
}
@@ -480,7 +487,8 @@ ble_gatt_eatt_write_cl_cb(uint16_t conn_handle,
480
487
struct ble_gatt_attr * attr , void * arg )
481
488
{
482
489
if (error == NULL || (error -> status != 0 && error -> status != BLE_HS_EDONE )) {
483
- BLE_EATT_LOG_DEBUG ("eatt: Cannot write to Client Supported features on peer device\n" );
490
+ BLE_EATT_LOG_DEBUG ("eatt: Cannot write to Client Supported"
491
+ "features on peer device\n" );
484
492
return 0 ;
485
493
}
486
494
@@ -516,8 +524,11 @@ ble_gatt_eatt_write_cl_cb(uint16_t conn_handle,
516
524
}
517
525
518
526
delay = (delay_rand % 5 ) + 2 * (desc .conn_latency + 1 ) * desc .conn_itvl ;
527
+
519
528
eatt -> conn_handle = conn_handle ;
520
- os_callout_reset (& eatt -> auto_conn_delay , OS_TICKS_PER_SEC / 1000 * delay );
529
+
530
+ os_callout_reset (& eatt -> auto_conn_delay ,
531
+ OS_TICKS_PER_SEC / 1000 * delay );
521
532
} else if (desc .role == BLE_GAP_ROLE_MASTER && eatt -> used_channels == 0 ) {
522
533
ble_eatt_connect (conn_handle , MYNEWT_VAL (BLE_EATT_CHAN_PER_CONN ));
523
534
}
@@ -535,7 +546,8 @@ ble_gatt_eatt_read_cl_uuid_cb(uint16_t conn_handle,
535
546
int rc ;
536
547
537
548
if (error == NULL || (error -> status != 0 && error -> status != BLE_HS_EDONE )) {
538
- BLE_EATT_LOG_DEBUG ("eatt: Cannot find Client Supported features on peer device\n" );
549
+ BLE_EATT_LOG_DEBUG ("eatt: Cannot find Client Supported features"
550
+ "on peer device\n" );
539
551
return BLE_HS_EDONE ;
540
552
}
541
553
@@ -546,7 +558,8 @@ ble_gatt_eatt_read_cl_uuid_cb(uint16_t conn_handle,
546
558
547
559
if (error -> status == 0 ) {
548
560
client_supported_feat = ble_svc_gatt_get_local_cl_supported_feat ();
549
- rc = ble_gattc_write_flat (conn_handle , attr -> handle , & client_supported_feat , 1 ,
561
+ rc = ble_gattc_write_flat (conn_handle , attr -> handle ,
562
+ & client_supported_feat , 1 ,
550
563
ble_gatt_eatt_write_cl_cb , NULL );
551
564
BLE_EATT_LOG_DEBUG ("eatt: %s , write rc = %d \n" , __func__ , rc );
552
565
assert (rc == 0 );
@@ -584,10 +597,14 @@ ble_eatt_gap_event(struct ble_gap_event *event, void *arg)
584
597
return 0 ;
585
598
}
586
599
587
- BLE_EATT_LOG_DEBUG ("eatt: Encryption enabled, connecting EATT (conn_handle=0x%04x)\n" ,
588
- event -> enc_change .conn_handle );
600
+ #if (MYNEWT_VAL (BLE_EATT_AUTO_CONNECT ))
601
+ BLE_EATT_LOG_DEBUG ("eatt: Encryption enabled,"
602
+ "connecting EATT (conn_handle=0x%04x)\n" ,
603
+ event -> enc_change .conn_handle );
604
+ #endif
589
605
590
- ble_npl_event_set_arg (& g_read_sup_cl_feat_ev , UINT_TO_POINTER (event -> enc_change .conn_handle ));
606
+ ble_npl_event_set_arg (& g_read_sup_cl_feat_ev ,
607
+ UINT_TO_POINTER (event -> enc_change .conn_handle ));
591
608
ble_npl_eventq_put (ble_hs_evq_get (), & g_read_sup_cl_feat_ev );
592
609
593
610
break ;
@@ -625,7 +642,8 @@ ble_eatt_release_chan(uint16_t conn_handle, uint8_t op)
625
642
eatt = ble_eatt_find_by_conn_handle_and_busy_op (conn_handle , op );
626
643
if (!eatt ) {
627
644
BLE_EATT_LOG_WARN ("ble_eatt_release_chan:"
628
- "EATT not found for conn_handle 0x%04x, operation 0x%02\n" , conn_handle , op );
645
+ "EATT not found for conn_handle 0x%04x,"
646
+ "operation 0x%02\n" , conn_handle , op );
629
647
return ;
630
648
}
631
649
@@ -701,15 +719,17 @@ ble_eatt_connect(uint16_t conn_handle, uint8_t chan_num)
701
719
}
702
720
703
721
if (chan_num == 0 || chan_num > MYNEWT_VAL (BLE_EATT_CHAN_PER_CONN )) {
704
- BLE_EATT_LOG_WARN ("ble_eatt_connect | Invalid channel number\n" );
722
+ BLE_EATT_LOG_WARN ("ble_eatt_connect: Invalid channel number\n" );
705
723
return ;
706
724
}
707
725
708
726
/* Get number of free channels for this connection */
709
- free_channels = MYNEWT_VAL (BLE_EATT_CHAN_PER_CONN ) - ble_eatt_used_channels (conn_handle );
727
+ free_channels =
728
+ MYNEWT_VAL (BLE_EATT_CHAN_PER_CONN ) -
729
+ ble_eatt_used_channels (conn_handle );
710
730
711
731
if (free_channels == 0 ) {
712
- BLE_EATT_LOG_ERROR ("ble_eatt_connect | No free channel slots\n" );
732
+ BLE_EATT_LOG_ERROR ("ble_eatt_connect: No free channel slots\n" );
713
733
return ;
714
734
}
715
735
@@ -739,11 +759,15 @@ ble_eatt_init(ble_eatt_att_rx_fn att_rx_cb)
739
759
BLE_HS_DBG_ASSERT_EVAL (rc == 0 );
740
760
741
761
742
- ble_gap_event_listener_register (& ble_eatt_listener , ble_eatt_gap_event , NULL );
743
- ble_l2cap_create_server (BLE_EATT_PSM , MYNEWT_VAL (BLE_EATT_MTU ), ble_eatt_l2cap_event_fn , NULL );
762
+ ble_gap_event_listener_register (& ble_eatt_listener ,
763
+ ble_eatt_gap_event , NULL );
764
+
765
+ ble_l2cap_create_server (BLE_EATT_PSM , MYNEWT_VAL (BLE_EATT_MTU ),
766
+ ble_eatt_l2cap_event_fn , NULL );
744
767
745
768
ble_npl_event_init (& g_read_sup_cl_feat_ev , ble_gatt_eatt_read_cl_uuid , NULL );
746
769
747
770
ble_eatt_att_rx_cb = att_rx_cb ;
748
771
}
772
+
749
773
#endif
0 commit comments