@@ -63,6 +63,7 @@ static bool phase_bd_addr = false;
63
63
static bool phase_tx_power = false ;
64
64
static bool phase_reset = false ;
65
65
static bool phase_cnx = false ;
66
+ static bool phase_running = false ;
66
67
67
68
HCISharedMemTransportClass::HCISharedMemTransportClass (BLEChip_t ble_chip) :
68
69
_ble_chip(ble_chip)
@@ -99,13 +100,20 @@ static void evt_received(TL_EvtPacket_t *hcievt)
99
100
#endif /* PRINT_HCI_DATA */
100
101
#endif /* DEBUG */
101
102
103
+ if (phase_running == false ) {
102
104
/* check the Rx event of complete the previous bd_addr opcode 0xfc0c */
103
105
if ((hcievt->evtserial .evt .evtcode == TL_BLEEVT_CC_OPCODE) &&
104
106
(hcievt->evtserial .evt .payload [0 ] == 0x01 ) &&
105
107
(hcievt->evtserial .evt .payload [1 ] == 0x0C ) &&
106
108
(hcievt->evtserial .evt .payload [2 ] == 0xFC )) {
107
- phase_bd_addr = true ;
109
+ phase_bd_addr = true ;
108
110
/* rx data is no more useful */
111
+ if (hcievt->evtserial .evt .payload [3 ] != 0 ) {
112
+ #if defined(DEBUG)
113
+ printf (" Error: wrong BD Addr\r\n " );
114
+ #endif /* DEBUG */
115
+ return ;
116
+ }
109
117
break ;
110
118
}
111
119
/* check the Rx event of complete the previous tx power opcode 0xFC0F */
@@ -115,17 +123,32 @@ static void evt_received(TL_EvtPacket_t *hcievt)
115
123
(hcievt->evtserial .evt .payload [2 ] == 0xFC )) {
116
124
phase_tx_power = true ;
117
125
/* rx data is no more useful */
126
+ if (hcievt->evtserial .evt .payload [3 ] != 0 ) {
127
+ #if defined(DEBUG)
128
+ printf (" Error: wrong Tx power\r\n " );
129
+ #endif /* DEBUG */
130
+ return ;
131
+ }
118
132
break ;
119
133
}
120
-
121
134
/* check if the reset phase is in progress (opcode is 0x0C03) */
122
135
if ((hcievt->evtserial .evt .evtcode == TL_BLEEVT_CC_OPCODE) &&
123
136
(hcievt->evtserial .evt .payload [0 ] == 0x01 ) &&
124
137
(hcievt->evtserial .evt .payload [1 ] == 0x03 ) &&
125
138
(hcievt->evtserial .evt .payload [2 ] == 0x0C )) {
126
139
phase_reset = true ;
140
+ if (hcievt->evtserial .evt .payload [3 ] != 0 ) {
141
+ #if defined(DEBUG)
142
+ printf (" Error: wrong reset\r\n " );
143
+ #endif /* DEBUG */
144
+ return ;
145
+ }
127
146
}
128
147
148
+ if ((phase_bd_addr == true ) && (phase_bd_addr == true ) && (phase_reset == true )) {
149
+ phase_running = true ;
150
+ }
151
+ }
129
152
/* check if the connection phase is up (event code is 0x3E) */
130
153
if ((hcievt->evtserial .evt .evtcode == 0x3E )) {
131
154
phase_cnx = true ;
@@ -633,7 +656,7 @@ static int bt_ipm_set_addr(void)
633
656
634
657
/* now wait for the corresponding Rx event */
635
658
while (!phase_bd_addr);
636
- phase_bd_addr = false ; /* this sequence is now complete */
659
+ /* this sequence is now complete */
637
660
638
661
return 1 ; /* success */
639
662
} else {
@@ -662,7 +685,7 @@ static int bt_ipm_set_power(void)
662
685
663
686
/* now wait for the corresponding Rx event */
664
687
while (!phase_tx_power);
665
- phase_tx_power = false ; /* this sequence is now complete */
688
+ /* this sequence is now complete */
666
689
667
690
return 1 ; /* success */
668
691
}
0 commit comments