File tree Expand file tree Collapse file tree 2 files changed +16
-11
lines changed
devices/ble_hci/common-hal/_bleio Expand file tree Collapse file tree 2 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -331,27 +331,27 @@ hci_result_t hci_poll_for_incoming_pkt(void) {
331
331
332
332
switch (rx_buffer [0 ]) {
333
333
case H4_ACL :
334
- if (rx_idx > sizeof (h4_hci_acl_pkt_t )) {
334
+ if (rx_idx >= sizeof (h4_hci_acl_pkt_t )) {
335
335
const size_t total_len =
336
336
sizeof (h4_hci_acl_pkt_t ) + ((h4_hci_acl_pkt_t * ) rx_buffer )-> data_len ;
337
337
if (rx_idx == total_len ) {
338
338
packet_is_complete = true;
339
339
}
340
340
if (rx_idx > total_len ) {
341
- mp_printf ( & mp_plat_print , "acl: rx_idx > total_len\n" ) ;
341
+ return HCI_PACKET_SIZE_ERROR ;
342
342
}
343
343
}
344
344
break ;
345
345
346
346
case H4_EVT :
347
- if (rx_idx > sizeof (h4_hci_evt_pkt_t )) {
347
+ if (rx_idx >= sizeof (h4_hci_evt_pkt_t )) {
348
348
const size_t total_len =
349
349
sizeof (h4_hci_evt_pkt_t ) + ((h4_hci_evt_pkt_t * ) rx_buffer )-> param_len ;
350
350
if (rx_idx == total_len ) {
351
351
packet_is_complete = true;
352
352
}
353
353
if (rx_idx > total_len ) {
354
- mp_printf ( & mp_plat_print , "evt: rx_idx > total_len\n" ) ;
354
+ return HCI_PACKET_SIZE_ERROR ;
355
355
}
356
356
}
357
357
break ;
@@ -786,6 +786,10 @@ void hci_check_error(hci_result_t result) {
786
786
mp_raise_bleio_BluetoothError (translate ("Error writing to HCI adapter" ));
787
787
return ;
788
788
789
+ case HCI_PACKET_SIZE_ERROR :
790
+ mp_raise_RuntimeError (translate ("HCI packet size mismatch" ));
791
+ return ;
792
+
789
793
case HCI_ATT_ERROR :
790
794
mp_raise_RuntimeError (translate ("Error in ATT protocol code" ));
791
795
return ;
Original file line number Diff line number Diff line change 29
29
typedef struct _bleio_adapter_obj_t bleio_adapter_obj_t ;
30
30
31
31
// An hci_result_t is one of the HCI_x values below,
32
- // or is it > 0 and is an HCI command status value (see hci_include/hci_err.h)
32
+ // or it is > 0 and is an HCI command status value (see hci_include/hci_err.h)
33
33
typedef int hci_result_t ;
34
- #define HCI_OK (0)
35
- #define HCI_RESPONSE_TIMEOUT (-1)
36
- #define HCI_WRITE_TIMEOUT (-2)
37
- #define HCI_READ_ERROR (-3)
38
- #define HCI_WRITE_ERROR (-4)
39
- #define HCI_ATT_ERROR (-5)
34
+ #define HCI_OK (0)
35
+ #define HCI_RESPONSE_TIMEOUT (-1)
36
+ #define HCI_WRITE_TIMEOUT (-2)
37
+ #define HCI_READ_ERROR (-3)
38
+ #define HCI_WRITE_ERROR (-4)
39
+ #define HCI_ATT_ERROR (-5)
40
+ #define HCI_PACKET_SIZE_ERROR (-6)
40
41
41
42
extern void bleio_hci_reset (void );
42
43
You can’t perform that action at this time.
0 commit comments