Skip to content

Commit 2a609ce

Browse files
nibmle/eatt: Improve formatting
Improve formatting to be more consistent Break some lines so they don't exceed 80 column rule. Add #if for auto-connect log.
1 parent 8d56513 commit 2a609ce

File tree

1 file changed

+56
-32
lines changed

1 file changed

+56
-32
lines changed

nimble/host/src/ble_eatt.c

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ ble_eatt_prepare_rx_sdu(struct ble_l2cap_chan *chan)
172172

173173
rc = ble_l2cap_recv_ready(chan, om);
174174
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);
177177
os_mbuf_free_chain(om);
178178
}
179179

@@ -279,10 +279,6 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
279279
case BLE_L2CAP_EVENT_COC_CONNECTED:
280280
eatt = ble_eatt_find_by_conn_handle(event->connect.conn_handle);
281281

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-
286282
if (event->connect.status == BLE_HS_ENOMEM && eatt->collision_ctrl) {
287283
BLE_EATT_LOG_DEBUG("eatt: Connection collision\n");
288284

@@ -296,7 +292,8 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
296292

297293
coll_delay = (rand_part % 5) + 2 * (desc.conn_latency + 1) * desc.conn_itvl;
298294

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);
300297

301298
return 0;
302299
}
@@ -315,17 +312,22 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
315312

316313
/* Increase used channel number on connected event */
317314
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);
320319
break;
321320
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);
325325

326326
eatt = ble_eatt_find_by_conn_handle(event->disconnect.conn_handle);
327327
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);
329331
return 0;
330332
}
331333

@@ -341,13 +343,16 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
341343
break;
342344
case BLE_L2CAP_EVENT_COC_ACCEPT:
343345

346+
344347
/* Lookup if EATT already exists for this connection */
345348
eatt = ble_eatt_find_by_conn_handle(event->accept.conn_handle);
346349
if (!eatt) {
347350
eatt = ble_eatt_alloc();
348351
} else {
349352
/* 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;
351356

352357
if (free_channels == 0) {
353358
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)
360365

361366
/* We do not increase number of used channels
362367
* 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.
364369
*/
365370
eatt->accept_chans++;
366371

@@ -423,7 +428,8 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
423428
return BLE_HS_EREJECT;
424429
}
425430

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);
427433
if (event->receive.sdu_rx) {
428434
os_mbuf_free_chain(event->receive.sdu_rx);
429435
event->receive.sdu_rx = NULL;
@@ -460,15 +466,16 @@ ble_eatt_setup_cb(struct ble_npl_event *ev)
460466
return;
461467
}
462468

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);
464471

465472
rc = ble_l2cap_enhanced_connect(eatt->conn_handle, BLE_EATT_PSM,
466473
MYNEWT_VAL(BLE_EATT_MTU),
467474
eatt->chan_num, &om,
468475
ble_eatt_l2cap_event_fn, eatt);
469476
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);
472479
os_mbuf_free_chain(om);
473480
ble_eatt_free(eatt);
474481
}
@@ -480,7 +487,8 @@ ble_gatt_eatt_write_cl_cb(uint16_t conn_handle,
480487
struct ble_gatt_attr *attr, void *arg)
481488
{
482489
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");
484492
return 0;
485493
}
486494

@@ -516,8 +524,11 @@ ble_gatt_eatt_write_cl_cb(uint16_t conn_handle,
516524
}
517525

518526
delay = (delay_rand % 5) + 2 * (desc.conn_latency + 1) * desc.conn_itvl;
527+
519528
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);
521532
} else if (desc.role == BLE_GAP_ROLE_MASTER && eatt->used_channels == 0) {
522533
ble_eatt_connect(conn_handle, MYNEWT_VAL(BLE_EATT_CHAN_PER_CONN));
523534
}
@@ -535,7 +546,8 @@ ble_gatt_eatt_read_cl_uuid_cb(uint16_t conn_handle,
535546
int rc;
536547

537548
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");
539551
return BLE_HS_EDONE;
540552
}
541553

@@ -546,7 +558,8 @@ ble_gatt_eatt_read_cl_uuid_cb(uint16_t conn_handle,
546558

547559
if (error->status == 0) {
548560
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,
550563
ble_gatt_eatt_write_cl_cb, NULL);
551564
BLE_EATT_LOG_DEBUG("eatt: %s , write rc = %d \n", __func__, rc);
552565
assert(rc == 0);
@@ -584,10 +597,14 @@ ble_eatt_gap_event(struct ble_gap_event *event, void *arg)
584597
return 0;
585598
}
586599

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
589605

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));
591608
ble_npl_eventq_put(ble_hs_evq_get(), &g_read_sup_cl_feat_ev);
592609

593610
break;
@@ -625,7 +642,8 @@ ble_eatt_release_chan(uint16_t conn_handle, uint8_t op)
625642
eatt = ble_eatt_find_by_conn_handle_and_busy_op(conn_handle, op);
626643
if (!eatt) {
627644
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);
629647
return;
630648
}
631649

@@ -701,15 +719,17 @@ ble_eatt_connect(uint16_t conn_handle, uint8_t chan_num)
701719
}
702720

703721
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");
705723
return;
706724
}
707725

708726
/* 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);
710730

711731
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");
713733
return;
714734
}
715735

@@ -739,11 +759,15 @@ ble_eatt_init(ble_eatt_att_rx_fn att_rx_cb)
739759
BLE_HS_DBG_ASSERT_EVAL(rc == 0);
740760

741761

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);
744767

745768
ble_npl_event_init(&g_read_sup_cl_feat_ev, ble_gatt_eatt_read_cl_uuid, NULL);
746769

747770
ble_eatt_att_rx_cb = att_rx_cb;
748771
}
772+
749773
#endif

0 commit comments

Comments
 (0)