apps/listener/src/bleprph.c
static int
bleprph_gap_event(struct ble_gap_event *event, void *arg)
{
    struct ble_gap_conn_desc desc;
    int rc;

    switch (event->type) {
    case BLE_GAP_EVENT_CONNECT:
        /* A new connection was established or a connection attempt failed. */
        BLEPRPH_LOG(INFO, "connection %s; status=%d ",
                       event->connect.status == 0 ? "established" : "failed",
                       event->connect.status);
        if (event->connect.status == 0) {
            rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
            assert(rc == 0);

#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
            phy_conn_changed(event->connect.conn_handle);
#endif
        }
        BLEPRPH_LOG(INFO, "\n");

        if (event->connect.status != 0) {
            /* Connection failed; resume advertising. */
            bleprph_advertise();
        }
        return 0;

    case BLE_GAP_EVENT_DISCONNECT:
        BLEPRPH_LOG(INFO, "disconnect; reason=%d ", event->disconnect.reason);
        BLEPRPH_LOG(INFO, "\n");

#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
        phy_conn_changed(CONN_HANDLE_INVALID);
#endif

        /* Connection terminated; resume advertising. */
        bleprph_advertise();
        return 0;

    case BLE_GAP_EVENT_CONN_UPDATE:
        /* The central has updated the connection parameters. */
        BLEPRPH_LOG(INFO, "connection updated; status=%d ",
                    event->conn_update.status);
        rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
        assert(rc == 0);
        BLEPRPH_LOG(INFO, "\n");
        return 0;

    case BLE_GAP_EVENT_ADV_COMPLETE:
        BLEPRPH_LOG(INFO, "advertise complete; reason=%d",
                    event->adv_complete.reason);
        bleprph_advertise();
        return 0;

    case BLE_GAP_EVENT_ENC_CHANGE:
        /* Encryption has been enabled or disabled for this connection. */
        BLEPRPH_LOG(INFO, "encryption change event; status=%d ",
                    event->enc_change.status);
        rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
        assert(rc == 0);
        BLEPRPH_LOG(INFO, "\n");
        return 0;

    case BLE_GAP_EVENT_SUBSCRIBE:
        BLEPRPH_LOG(INFO, "subscribe event; conn_handle=%d attr_handle=%d "
                          "reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
                    event->subscribe.conn_handle,
                    event->subscribe.attr_handle,
                    event->subscribe.reason,
                    event->subscribe.prev_notify,
                    event->subscribe.cur_notify,
                    event->subscribe.prev_indicate,
                    event->subscribe.cur_indicate);
        return 0;

    case BLE_GAP_EVENT_MTU:
        BLEPRPH_LOG(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n",
                    event->mtu.conn_handle,
                    event->mtu.channel_id,
                    event->mtu.value);
        return 0;

    case BLE_GAP_EVENT_REPEAT_PAIRING:
        /* We already have a bond with the peer, but it is attempting to
         * establish a new secure link.  This app sacrifices security for
         * convenience: just throw away the old bond and accept the new link.
         */

        /* Delete the old bond. */
        rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
        assert(rc == 0);
        ble_store_util_delete_peer(&desc.peer_id_addr);

        /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should
         * continue with the pairing operation.
         */
        return BLE_GAP_REPEAT_PAIRING_RETRY;

#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
    case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE:
        /* XXX: assume symmetric phy for now */
        phy_update(event->phy_updated.tx_phy);
        return 0;
#endif
    }

    return 0;
}
/**
 * The nimble host executes this callback when a GAP event occurs.  The
 * application associates a GAP event callback with each connection that forms.
 * bleprph uses the same callback for all connections.
 *
 * @param event                 The type of event being signalled.
 * @param ctxt                  Various information pertaining to the event.
 * @param arg                   Application-specified argument; unuesd by
 *                                  bleprph.
 *
 * @return                      0 if the application successfully handled the
 *                                  event; nonzero on failure.  The semantics
 *                                  of the return code is specific to the
 *                                  particular GAP event being signalled.
 */
The nimble host executes this callback when a GAP event occurs.  The
application associates a GAP event callback with each connection that forms.
bleprph uses the same callback for all connections.

@param event                 The type of event being signalled.
@param ctxt                  Various information pertaining to the event.
@param arg                   Application-specified argument; unuesd by
bleprph.

@return                      0 if the application successfully handled the
event; nonzero on failure.  The semantics
of the return code is specific to the
particular GAP event being signalled.
The nimble host executes this callback when a GAP event occurs . The application associates a GAP event callback with each connection that forms . bleprph uses the same callback for all connections . @param event The type of event being signalled . @param ctxt Various information pertaining to the event . @param arg Application - specified argument ; unuesd by bleprph . @return 0 if the application successfully handled the event ; nonzero on failure . The semantics of the return code is specific to the particular GAP event being signalled .
static int
bleprph_gap_event(struct ble_gap_event *event, void *arg)
{
    struct ble_gap_conn_desc desc;
    int rc;
    switch (event->type) {
    case BLE_GAP_EVENT_CONNECT:
        BLEPRPH_LOG(INFO, "connection %s; status=%d ",
                       event->connect.status == 0 ? "established" : "failed",
                       event->connect.status);
        if (event->connect.status == 0) {
            rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
            assert(rc == 0);
#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
            phy_conn_changed(event->connect.conn_handle);
#endif
        }
        BLEPRPH_LOG(INFO, "\n");
        if (event->connect.status != 0) {
            bleprph_advertise();
        }
        return 0;
    case BLE_GAP_EVENT_DISCONNECT:
        BLEPRPH_LOG(INFO, "disconnect; reason=%d ", event->disconnect.reason);
        BLEPRPH_LOG(INFO, "\n");
#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
        phy_conn_changed(CONN_HANDLE_INVALID);
#endif
        bleprph_advertise();
        return 0;
    case BLE_GAP_EVENT_CONN_UPDATE:
        BLEPRPH_LOG(INFO, "connection updated; status=%d ",
                    event->conn_update.status);
        rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
        assert(rc == 0);
        BLEPRPH_LOG(INFO, "\n");
        return 0;
    case BLE_GAP_EVENT_ADV_COMPLETE:
        BLEPRPH_LOG(INFO, "advertise complete; reason=%d",
                    event->adv_complete.reason);
        bleprph_advertise();
        return 0;
    case BLE_GAP_EVENT_ENC_CHANGE:
        BLEPRPH_LOG(INFO, "encryption change event; status=%d ",
                    event->enc_change.status);
        rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
        assert(rc == 0);
        BLEPRPH_LOG(INFO, "\n");
        return 0;
    case BLE_GAP_EVENT_SUBSCRIBE:
        BLEPRPH_LOG(INFO, "subscribe event; conn_handle=%d attr_handle=%d "
                          "reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
                    event->subscribe.conn_handle,
                    event->subscribe.attr_handle,
                    event->subscribe.reason,
                    event->subscribe.prev_notify,
                    event->subscribe.cur_notify,
                    event->subscribe.prev_indicate,
                    event->subscribe.cur_indicate);
        return 0;
    case BLE_GAP_EVENT_MTU:
        BLEPRPH_LOG(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n",
                    event->mtu.conn_handle,
                    event->mtu.channel_id,
                    event->mtu.value);
        return 0;
    case BLE_GAP_EVENT_REPEAT_PAIRING:
        rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
        assert(rc == 0);
        ble_store_util_delete_peer(&desc.peer_id_addr);
        return BLE_GAP_REPEAT_PAIRING_RETRY;
#if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT)
    case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE:
        phy_update(event->phy_updated.tx_phy);
        return 0;
#endif
    }
    return 0;
}
static int bleprph_gap_event ( struct ble_gap_event * event , void * arg ) { struct ble_gap_conn_desc desc ; int rc ; switch ( event -> type ) { case BLE_GAP_EVENT_CONNECT : BLEPRPH_LOG ( INFO , " " , event -> connect . status == 0 ? " " : " " , event -> connect . status ) ; if ( event -> connect . status == 0 ) { rc = ble_gap_conn_find ( event -> connect . conn_handle , & desc ) ; assert ( rc == 0 ) ; #if MYNEWT_VAL ( BLEPRPH_LE_PHY_SUPPORT ) phy_conn_changed ( event -> connect . conn_handle ) ; #endif } BLEPRPH_LOG ( INFO , " \n " ) ; if ( event -> connect . status != 0 ) { bleprph_advertise ( ) ; } return 0 ; case BLE_GAP_EVENT_DISCONNECT : BLEPRPH_LOG ( INFO , " " , event -> disconnect . reason ) ; BLEPRPH_LOG ( INFO , " \n " ) ; #if MYNEWT_VAL ( BLEPRPH_LE_PHY_SUPPORT ) phy_conn_changed ( CONN_HANDLE_INVALID ) ; #endif bleprph_advertise ( ) ; return 0 ; case BLE_GAP_EVENT_CONN_UPDATE : BLEPRPH_LOG ( INFO , " " , event -> conn_update . status ) ; rc = ble_gap_conn_find ( event -> connect . conn_handle , & desc ) ; assert ( rc == 0 ) ; BLEPRPH_LOG ( INFO , " \n " ) ; return 0 ; case BLE_GAP_EVENT_ADV_COMPLETE : BLEPRPH_LOG ( INFO , " " , event -> adv_complete . reason ) ; bleprph_advertise ( ) ; return 0 ; case BLE_GAP_EVENT_ENC_CHANGE : BLEPRPH_LOG ( INFO , " " , event -> enc_change . status ) ; rc = ble_gap_conn_find ( event -> connect . conn_handle , & desc ) ; assert ( rc == 0 ) ; BLEPRPH_LOG ( INFO , " \n " ) ; return 0 ; case BLE_GAP_EVENT_SUBSCRIBE : BLEPRPH_LOG ( INFO , " " " \n " , event -> subscribe . conn_handle , event -> subscribe . attr_handle , event -> subscribe . reason , event -> subscribe . prev_notify , event -> subscribe . cur_notify , event -> subscribe . prev_indicate , event -> subscribe . cur_indicate ) ; return 0 ; case BLE_GAP_EVENT_MTU : BLEPRPH_LOG ( INFO , " \n " , event -> mtu . conn_handle , event -> mtu . channel_id , event -> mtu . value ) ; return 0 ; case BLE_GAP_EVENT_REPEAT_PAIRING : rc = ble_gap_conn_find ( event -> repeat_pairing . conn_handle , & desc ) ; assert ( rc == 0 ) ; ble_store_util_delete_peer ( & desc . peer_id_addr ) ; return BLE_GAP_REPEAT_PAIRING_RETRY ; #if MYNEWT_VAL ( BLEPRPH_LE_PHY_SUPPORT ) case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE : phy_update ( event -> phy_updated . tx_phy ) ; return 0 ; #endif } return 0 ; }
The nimble host executes this callback when a GAP event occurs.
The nimble host executes this callback when a GAP event occurs .
/* A new connection was established or a connection attempt failed. */ /* Connection failed; resume advertising. */ /* Connection terminated; resume advertising. */ /* The central has updated the connection parameters. */ /* Encryption has been enabled or disabled for this connection. */ /* We already have a bond with the peer, but it is attempting to
         * establish a new secure link.  This app sacrifices security for
         * convenience: just throw away the old bond and accept the new link.
         */ /* Delete the old bond. */ /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should
         * continue with the pairing operation.
         */ /* XXX: assume symmetric phy for now */