@@ -147,29 +147,63 @@ void BLECentral::clearBonds(void)
147
147
void BLECentral::_event_handler (ble_evt_t * evt)
148
148
{
149
149
// conn handle has fixed offset regardless of event type
150
- const uint16_t evt_conn_hdl = evt->evt .common_evt .conn_handle ;
150
+ const uint16_t conn_hdl = evt->evt .common_evt .conn_handle ;
151
151
152
152
/* PrPh handle connection is already filtered. Only handle Central events or
153
- * connection handle is BLE_CONN_HANDLE_INVALID (e.g BLE_GAP_EVT_ADV_REPORT)
154
- */
153
+ * connection handle is BLE_CONN_HANDLE_INVALID (e.g BLE_GAP_EVT_ADV_REPORT) */
155
154
switch ( evt->header .evt_id )
156
155
{
157
156
case BLE_GAP_EVT_CONNECTED:
158
- if ( Bluefruit.Gap .getRole (evt_conn_hdl ) == BLE_GAP_ROLE_CENTRAL)
157
+ if ( Bluefruit.Gap .getRole (conn_hdl ) == BLE_GAP_ROLE_CENTRAL)
159
158
{
160
159
// Invoke callback
161
- if ( _connect_cb) ada_callback (NULL , _connect_cb, evt_conn_hdl );
160
+ if ( _connect_cb) ada_callback (NULL , _connect_cb, conn_hdl );
162
161
}
163
162
break ;
164
163
165
164
case BLE_GAP_EVT_DISCONNECTED:
166
- if ( Bluefruit.Gap .getRole (evt_conn_hdl ) == BLE_GAP_ROLE_CENTRAL)
165
+ if ( Bluefruit.Gap .getRole (conn_hdl ) == BLE_GAP_ROLE_CENTRAL)
167
166
{
168
167
// Invoke callback reason is BLE_HCI_STATUS code
169
- if ( _disconnect_cb) ada_callback (NULL , _disconnect_cb, evt_conn_hdl , evt->evt .gap_evt .params .disconnected .reason );
168
+ if ( _disconnect_cb) ada_callback (NULL , _disconnect_cb, conn_hdl , evt->evt .gap_evt .params .disconnected .reason );
170
169
}
171
170
break ;
172
171
172
+ case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
173
+ {
174
+ ble_gap_conn_params_t * request_param = &evt->evt .gap_evt .params .conn_param_update_request .conn_params ;
175
+
176
+ PRINT_INT (request_param->min_conn_interval );
177
+ PRINT_INT (request_param->max_conn_interval );
178
+ PRINT_INT (request_param->slave_latency );
179
+ PRINT_INT (request_param->conn_sup_timeout );
180
+
181
+ // Accept request parameter if it is within our supported range, otherwise reject
182
+ if ( ( request_param->max_conn_interval < _ppcp_min_conn ) || ( request_param->min_conn_interval > _ppcp_max_conn ) )
183
+ {
184
+ LOG_LV1 (" GAP" , " Reject Conn Param Update Request: our = ( %.2f, %.2f ), request = ( %.2f, %.2f )" ,
185
+ ppcp_min_conn*1 .25f , _ppcp_max_conn*1 .25f , request_param->min_conn_interval *1 .25f , request_param->max_conn_interval *1 .25f );
186
+
187
+ sd_ble_gap_conn_param_update (conn_hdl, NULL ); // reject request
188
+ }else
189
+ {
190
+ uint16_t const conn_interval = max16 (_ppcp_min_conn, request_param->min_conn_interval );
191
+
192
+ ble_gap_conn_params_t resp_param =
193
+ {
194
+ .min_conn_interval = conn_interval,
195
+ .max_conn_interval = conn_interval, // central set min = max
196
+ .slave_latency = request_param->slave_latency , // TODO check save latency
197
+ .conn_sup_timeout = request_param->conn_sup_timeout , // TODO check supervisor timeout
198
+ };
199
+
200
+ LOG_LV2 (" GAP" , " Conn Interval is updated to %.2f ms" , conn_interval*1 .25f );
201
+
202
+ sd_ble_gap_conn_param_update (conn_hdl, &resp_param);
203
+ }
204
+ }
205
+ break ;
206
+
173
207
default : break ;
174
208
}
175
209
}
0 commit comments