You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2022/09/26 14:04:46 UTC

[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #1372: apps: Add privacy samples

apache-mynewt-bot commented on PR #1372:
URL: https://github.com/apache/mynewt-nimble/pull/1372#issuecomment-1258092971

   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### apps/privacy_central/src/main.c
   <details>
   
   ```diff
   @@ -34,8 +34,8 @@
    
    /* irk is hardcoded */
    static const uint8_t irk[16] = {
   -        0xae, 0xaa, 0xbe, 0xef, 0xab, 0xcd, 0x13, 0x14,
   -        0x65, 0x23, 0xcb, 0xab, 0x4b, 0x8b, 0x90, 0x60,
   +    0xae, 0xaa, 0xbe, 0xef, 0xab, 0xcd, 0x13, 0x14,
   +    0x65, 0x23, 0xcb, 0xab, 0x4b, 0x8b, 0x90, 0x60,
    };
    
    static void
   @@ -82,62 +82,62 @@
    {
        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;
    }
   @@ -148,7 +148,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;
   @@ -156,30 +156,30 @@
        memset(&parsed_fields, 0, sizeof(parsed_fields));
    
        switch (event->type) {
   -        /* advertising report has been received during discovery procedure */
   -        case BLE_GAP_EVENT_DISC:
   -            ble_hs_adv_parse_fields(&parsed_fields, event->disc.data,
   +    /* advertising report has been received during discovery procedure */
   +    case BLE_GAP_EVENT_DISC:
   +        ble_hs_adv_parse_fields(&parsed_fields, event->disc.data,
                                        event->disc.length_data);
   -            /* Predefined UUID is compared to recieved one;
   -               if doesn't fit - end procedure and go back to scanning,
   -               else - connect. */
   -            uuid_cmp_result = ble_uuid_cmp(&predef_uuid.u, &parsed_fields.uuids128->u);
   -            if (!uuid_cmp_result) {
   -                MODLOG_DFLT(INFO, "Device with fitting UUID found, connecting...\n");
   -                ble_gap_disc_cancel();
   -                /* TODO: I do not understand this +2 addition well and do not know when should I use it, so this might be wrong (check the whole app)*/
   -                ble_gap_connect(g_own_addr_type+2, &(event->disc.addr), 10000,
   +        /* Predefined UUID is compared to recieved one;
   +           if doesn't fit - end procedure and go back to scanning,
   +           else - connect. */
   +        uuid_cmp_result = ble_uuid_cmp(&predef_uuid.u, &parsed_fields.uuids128->u);
   +        if (!uuid_cmp_result) {
   +            MODLOG_DFLT(INFO, "Device with fitting UUID found, connecting...\n");
   +            ble_gap_disc_cancel();
   +            /* TODO: I do not understand this +2 addition well and do not know when should I use it, so this might be wrong (check the whole app)*/
   +            ble_gap_connect(g_own_addr_type+2, &(event->disc.addr), 10000,
                                    NULL, conn_event, NULL);
   -            }
   -            break;
   -        case BLE_GAP_EVENT_DISC_COMPLETE:
   -            MODLOG_DFLT(INFO,"Discovery completed, reason: %d\n",
   +        }
   +        break;
   +    case BLE_GAP_EVENT_DISC_COMPLETE:
   +        MODLOG_DFLT(INFO,"Discovery completed, reason: %d\n",
                            event->disc_complete.reason);
   -            scan();
   -            break;
   -        default:
   -            MODLOG_DFLT(ERROR, "Discovery event not handled\n");
   -            break;
   +        scan();
   +        break;
   +    default:
   +        MODLOG_DFLT(ERROR, "Discovery event not handled\n");
   +        break;
        }
        return 0;
    }
   ```
   
   </details>
   
   #### apps/privacy_periph/src/main.c
   <details>
   
   ```diff
   @@ -36,8 +36,8 @@
    
    /* irk is hardcoded */
    static const uint8_t irk[16] = {
   -        0xde, 0xad, 0xbe, 0xef, 0xab, 0xcd, 0x13, 0x14,
   -        0x65, 0x23, 0xab, 0xab, 0x4d, 0x8b, 0x90, 0x60,
   +    0xde, 0xad, 0xbe, 0xef, 0xab, 0xcd, 0x13, 0x14,
   +    0x65, 0x23, 0xab, 0xab, 0x4d, 0x8b, 0x90, 0x60,
    };
    
    static void
   @@ -81,51 +81,51 @@
    gap_event(struct ble_gap_event *event, void *arg)
    {
        switch (event->type) {
   -        case BLE_GAP_EVENT_ADV_COMPLETE:
   -            console_printf("Advertising completed, termination code: %d\n",
   +    case BLE_GAP_EVENT_ADV_COMPLETE:
   +        console_printf("Advertising completed, termination code: %d\n",
                               event->adv_complete.reason);
   +        advertise();
   +        break;
   +    case BLE_GAP_EVENT_CONNECT:
   +        if (event->connect.status == 0) {
   +            console_printf("Connection was established\n");
   +            conn_handle = event->connect.conn_handle;
   +        } else {
   +            console_printf("Connection failed, error code: %i\n",
   +                               event->connect.status);
                advertise();
   -            break;
   -        case BLE_GAP_EVENT_CONNECT:
   -            if (event->connect.status == 0) {
   -                console_printf("Connection was established\n");
   -                conn_handle = event->connect.conn_handle;
   -            } else {
   -                console_printf("Connection failed, error code: %i\n",
   -                               event->connect.status);
   -                advertise();
   -            }
   -            break;
   -        case BLE_GAP_EVENT_DISCONNECT:
   -            console_printf("disconnect; reason=%d\n",
   +        }
   +        break;
   +    case BLE_GAP_EVENT_DISCONNECT:
   +        console_printf("disconnect; reason=%d\n",
                               event->disconnect.reason);
    
   -            /* reset conn_handle */
   -            conn_handle = BLE_HS_CONN_HANDLE_NONE;
   -
   -            /* Connection terminated; resume advertising */
   -            advertise();
   -            break;
   -        case BLE_GAP_EVENT_PASSKEY_ACTION:
   -            console_printf("passkey action event; action=%d\n",
   +        /* reset conn_handle */
   +        conn_handle = BLE_HS_CONN_HANDLE_NONE;
   +
   +        /* Connection terminated; resume advertising */
   +        advertise();
   +        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");
   -            break;
   -        case BLE_GAP_EVENT_ENC_CHANGE:
   -            console_printf("Encryption change, status: %d\n",
   +        break;
   +    case BLE_GAP_EVENT_ENC_CHANGE:
   +        console_printf("Encryption change, status: %d\n",
                               event->enc_change.status);
   -            break;
   -        default:
   -            MODLOG_DFLT(ERROR, "GAP event not handled,"
   +        break;
   +    default:
   +        MODLOG_DFLT(ERROR, "GAP event not handled,"
                                   "event code: %u\n", event->type);
   -            break;
   +        break;
        }
        return 0;
    }
   ```
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org