@@ -324,7 +324,7 @@ void evt_received(TL_EvtPacket_t *hcievt)
324324 }
325325}
326326
327- /* to send BLE packet to the SharedMem */
327+ /* to send BLE packet to the SharedMem : return nb of bytes actually written */
328328uint16_t mbox_write (uint8_t type, uint16_t len, const uint8_t *pData)
329329{
330330 TL_CmdPacket_t *bleCmdBuf = &BleCmdBuffer;
@@ -598,8 +598,10 @@ size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length)
598598 if ((data[1 ] == 0x03 ) && (data[2 ] == 0x0C )) {
599599 phase_reset = false ;
600600
601- mbox_write (data[0 ], (length - 1 ), msg_data);
602-
601+ if (mbox_write (data[0 ], (length - 1 ), msg_data) != (length - 1 )) {
602+ /* Error: no data are written */
603+ return 0 ;
604+ }
603605 /* capture event after HCI_RESET */
604606 while (!phase_reset);
605607
@@ -645,7 +647,7 @@ size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length)
645647
646648 return (length - 1 ); /* mbox_size of the HCI reset command */
647649 }
648- return 0 ; /* mbox_size of the HCI reset command */
650+ return 0 ; /* Error: no data written */
649651}
650652
651653// private:
@@ -810,7 +812,10 @@ int HCISharedMemTransportClass::bt_ipm_set_addr(void)
810812 data[5 ] = 6 ; /* is the length of the bd_addr table */
811813 memcpy (data + 6 , bd_addr_udn, 6 );
812814 /* send the ACI_HAL_WRITE_CONFIG_DATA */
813- mbox_write (data[0 ], 11 , &data[1 ]);
815+ if (mbox_write (data[0 ], 11 , &data[1 ]) != 11 ) {
816+ /* Error: no data are written */
817+ return 0 ;
818+ }
814819 /* now wait for the corresponding Rx event */
815820 return 1 ; /* success */
816821 }
@@ -847,7 +852,10 @@ int HCISharedMemTransportClass::bt_ipm_set_random_addr(void)
847852 data[5 ] = 6 ; /* is the length of the random address */
848853 memcpy (data + 6 , srd_bd_addr, 6 );
849854 /* send the ACI_HAL_WRITE_CONFIG_DATA */
850- mbox_write (data[0 ], 11 , &data[1 ]);
855+ if (mbox_write (data[0 ], 11 , &data[1 ]) != 11 ) {
856+ /* Error: no data are written */
857+ return 0 ;
858+ }
851859 /* now wait for the corresponding Rx event */
852860 return 1 ; /* success */
853861}
@@ -869,7 +877,10 @@ int HCISharedMemTransportClass::bt_ipm_set_power(void)
869877 data[5 ] = CFG_TX_POWER; /* PA_level */
870878
871879 /* send the SET_POWER */
872- mbox_write (data[0 ], 5 , &data[1 ]);
880+ if (mbox_write (data[0 ], 5 , &data[1 ]) != 5 ) {
881+ /* Error: no data are written */
882+ return 0 ;
883+ }
873884 /* now wait for the corresponding Rx event */
874885 return 1 ; /* success */
875886}
@@ -887,7 +898,10 @@ int HCISharedMemTransportClass::bt_ipm_gatt_init(void)
887898 data[3 ] = 0 ; /* the length */
888899
889900 /* send the GATT_INIT */
890- mbox_write (data[0 ], 3 , &data[1 ]);
901+ if (mbox_write (data[0 ], 3 , &data[1 ]) != 3 ) {
902+ /* Error: no data are written */
903+ return 0 ;
904+ }
891905 /* now wait for the corresponding Rx event */
892906 return 1 ; /* success */
893907}
@@ -910,7 +924,10 @@ int HCISharedMemTransportClass::bt_ipm_gap_init(void)
910924 data[6 ] = 0x00 ; /* device_name_char_len */
911925
912926 /* send the GAP_INIT */
913- mbox_write (data[0 ], 6 , &data[1 ]);
927+ if (mbox_write (data[0 ], 6 , &data[1 ]) != 6 ) {
928+ /* Error: no data are written */
929+ return 0 ;
930+ }
914931 /* now wait for the corresponding Rx event */
915932 return 1 ; /* success */
916933}
@@ -934,7 +951,10 @@ int HCISharedMemTransportClass::bt_ipm_get_random_addr(void)
934951 data[4 ] = 0x2E ; /* the offset */
935952
936953 /* send the ACI_READ_CONFIG_DATA_OPCODE */
937- mbox_write (data[0 ], 4 , &data[1 ]);
954+ if (mbox_write (data[0 ], 4 , &data[1 ]) != 4 ) {
955+ /* Error: no data are written */
956+ return 0 ;
957+ }
938958 /* now wait for the corresponding Rx event */
939959 return 1 ; /* success */
940960}
0 commit comments