mynewt-nimble icon indicating copy to clipboard operation
mynewt-nimble copied to clipboard

apps: Add privacy samples

Open m-gorecki opened this issue 2 years ago • 2 comments

Sample applications privacy_central and privacy_periph, showing how to configure privacy.

m-gorecki avatar Sep 26 '22 12:09 m-gorecki

Style check summary

Our coding style is here!

apps/privacy_central/src/main.c

@@ -82,64 +82,64 @@
 {
     static struct ble_gap_conn_desc conn_desc;
     switch (event->type) {
-        case BLE_GAP_EVENT_CONNECT:
-            if (event->connect.status == 0) {
-                console_printf("Connection was established\n");
-                conn_handle = event->connect.conn_handle;
-                /*
-                 * This function initiates the pairing if the devices are not
-                 * bonded yet or starts encryption if they are.
-                 */
-                ble_gap_security_initiate(event->connect.conn_handle);
-            } else {
-                console_printf("Connection failed, error code: %i\n",
+    case BLE_GAP_EVENT_CONNECT:
+        if (event->connect.status == 0) {
+            console_printf("Connection was established\n");
+            conn_handle = event->connect.conn_handle;
+            /*
+             * This function initiates the pairing if the devices are not
+             * bonded yet or starts encryption if they are.
+             */
+            ble_gap_security_initiate(event->connect.conn_handle);
+        } else {
+            console_printf("Connection failed, error code: %i\n",
                                event->connect.status);
-            }
-            break;
-        case BLE_GAP_EVENT_DISCONNECT:
-            console_printf("Disconnected, reason code: %i\n",
+        }
+        break;
+    case BLE_GAP_EVENT_DISCONNECT:
+        console_printf("Disconnected, reason code: %i\n",
                            event->disconnect.reason);
-            /*
-             * After disconnecting peer's identity should be resolved,
-             * so we can connect directly to it.
-             */
-            ble_gap_connect(g_own_addr_type, &peer_id_addr, 10000,
+        /*
+         * After disconnecting peer's identity should be resolved,
+         * so we can connect directly to it.
+         */
+        ble_gap_connect(g_own_addr_type, &peer_id_addr, 10000,
                             NULL, conn_event, NULL);
-            break;
-        case BLE_GAP_EVENT_PASSKEY_ACTION:
-            console_printf("passkey action event; action=%d\n",
+        break;
+    case BLE_GAP_EVENT_PASSKEY_ACTION:
+        console_printf("passkey action event; action=%d\n",
                            event->passkey.params.action);
-            if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
-                console_printf("Confirm or deny key: %lu\n",
-                               (unsigned long) event->passkey.params.numcmp);
-            }
-            break;
-        case BLE_GAP_EVENT_PARING_COMPLETE:
-            console_printf("Pairing attempt finished, pairing %s\n",
+        if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
+            console_printf("Confirm or deny key: %lu\n",
+                           (unsigned long) event->passkey.params.numcmp);
+        }
+        break;
+    case BLE_GAP_EVENT_PARING_COMPLETE:
+        console_printf("Pairing attempt finished, pairing %s\n",
                            event->pairing_complete.status == 0 ? "successful" : "failed");
+        ble_gap_terminate(event->connect.conn_handle, 0x13);
+        break;
+    case BLE_GAP_EVENT_ENC_CHANGE:
+        console_printf("Encryption change, status: %d\n",
+                           event->enc_change.status);
+        /*
+         * If the user does not confirm or deny the passkeys
+         * at a given time, encryption change will be timed out.
+         * In that case we disconnect.
+         */
+        if (event->enc_change.status == BLE_HS_ETIMEOUT) {
             ble_gap_terminate(event->connect.conn_handle, 0x13);
-            break;
-        case BLE_GAP_EVENT_ENC_CHANGE:
-            console_printf("Encryption change, status: %d\n",
-                           event->enc_change.status);
-            /*
-             * If the user does not confirm or deny the passkeys
-             * at a given time, encryption change will be timed out.
-             * In that case we disconnect.
-             */
-            if (event->enc_change.status == BLE_HS_ETIMEOUT) {
-                ble_gap_terminate(event->connect.conn_handle, 0x13);
-            }
-            break;
-        case BLE_GAP_EVENT_IDENTITY_RESOLVED:
-            console_printf("Identity resolved\n");
-            ble_gap_conn_find(event->identity_resolved.conn_handle, &conn_desc);
-            peer_id_addr = conn_desc.peer_id_addr;
-            break;
-        default:
-            MODLOG_DFLT(ERROR, "GAP event not handled,"
+        }
+        break;
+    case BLE_GAP_EVENT_IDENTITY_RESOLVED:
+        console_printf("Identity resolved\n");
+        ble_gap_conn_find(event->identity_resolved.conn_handle, &conn_desc);
+        peer_id_addr = conn_desc.peer_id_addr;
+        break;
+    default:
+        MODLOG_DFLT(ERROR, "GAP event not handled,"
                                "event code: %u\n", event->type);
-            break;
+        break;
     }
     return 0;
 }
@@ -149,7 +149,7 @@
 {
     /* predef_uuid stores information about UUID of device that we connect to */
     const ble_uuid128_t predef_uuid =
-          BLE_UUID128_INIT(0x92, 0x98, 0xae, 0x44, 0x47, 0x90, 0xfa, 0x83,
+        BLE_UUID128_INIT(0x92, 0x98, 0xae, 0x44, 0x47, 0x90, 0xfa, 0x83,
                            0x32, 0x4c, 0xb5, 0xaa, 0x6f, 0xaa, 0x8c, 0x72);
     struct ble_hs_adv_fields parsed_fields;
     int uuid_cmp_result;

apache-mynewt-bot avatar Sep 27 '22 12:09 apache-mynewt-bot

Those examples would be very useful

br101 avatar May 29 '23 09:05 br101