1 /**
2  * Copyright (c) 2017, Realsil Semiconductor Corporation. All rights reserved.
3  *
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include "os_mem.h"
10 #include "os_sync.h"
11 #include "os_sched.h"
12 
13 #include "hci_process.h"
14 #include "hci_tp.h"
15 #include "bt_board.h"
16 #include "trace_app.h"
17 #include "bt_types.h"
18 #include "hci_board.h"
19 #include "hci_uart.h"
20 
21 extern void hci_normal_start(void);
22 extern bool bt_check_iqk(void);
23 extern bool hci_start_iqk(void);
24 extern uint8_t  hci_tp_lgc_efuse[0x20];
25 extern uint8_t  hci_tp_phy_efuse[19];
26 
27 static uint8_t vendor_flow;
28 static uint8_t iqk_type = 0xff;
29 static uint8_t orignal_thermal[3];
30 
31 //====================hci_patch_util.c================
32 
hci_tp_read_local_ver(void)33 uint8_t hci_tp_read_local_ver(void)
34 {
35     uint8_t *p_cmd;
36     uint8_t *p;
37 
38     HCI_PRINT_TRACE0("hci_tp_read_local_ver");
39 
40     hci_normal_start();
41     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 4);
42     if (p_cmd != NULL)
43     {
44         p = p_cmd;
45         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
46         LE_UINT16_TO_STREAM(p, HCI_READ_LOCAL_VERSION_INFO);
47         LE_UINT8_TO_STREAM(p, 0); /* length */
48 
49         hci_adapter_send(p_cmd, p - p_cmd);
50         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
51         return HCI_TP_CHECK_OK;
52     }
53     else
54     {
55         return HCI_TP_CONFIG_FAIL;
56     }
57 }
58 
hci_read_local_version_check(uint8_t len,uint8_t * p_buf)59 uint8_t hci_read_local_version_check(uint8_t len, uint8_t *p_buf)
60 {
61     (void)len;
62     uint16_t    lmp_subver;
63     /* Skip status, hci version, hci revision, lmp version & manufacture name */
64     STREAM_SKIP_LEN(p_buf, 6);
65     LE_STREAM_TO_UINT16(lmp_subver, p_buf);
66     HCI_PRINT_INFO1("hci_tp_config: lmp_subver 0x%04x", lmp_subver);
67     if (lmp_subver != BT_DEFAUT_LMP_SUBVER)
68     {
69         HCI_PRINT_ERROR0("hci_tp_config: Patch already exists");
70         hci_board_debug("%s: Patch already exists\n",__FUNCTION__);
71         return HCI_TP_CONFIG_END;
72     }
73     else
74     {
75         //hci_board_debug("hci_tp_config: lmp_subver 0x%04x\n", lmp_subver);
76         return HCI_TP_CHECK_OK;
77     }
78 }
hci_tp_read_rom_ver(void)79 uint8_t hci_tp_read_rom_ver(void)
80 {
81     uint8_t *p_cmd;
82     uint8_t *p;
83 
84     HCI_PRINT_TRACE0("hci_tp_read_rom_ver");
85 
86     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 4);
87     if (p_cmd != NULL)
88     {
89         p = p_cmd;
90         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
91         LE_UINT16_TO_STREAM(p, HCI_VSC_READ_ROM_VERSION);
92         LE_UINT8_TO_STREAM(p, 0); /* length */
93 
94         hci_adapter_send(p_cmd, p - p_cmd);
95     }
96     else
97     {
98         return HCI_TP_CONFIG_FAIL;
99     }
100     return HCI_TP_CHECK_OK;
101 }
102 
103 extern bool hci_rtk_find_patch(uint8_t bt_hci_chip_id);
hci_read_rom_check(uint8_t len,uint8_t * p_buf)104 uint8_t hci_read_rom_check(uint8_t len, uint8_t *p_buf)
105 {
106     (void)len;
107     bool ret = false;
108     uint8_t    rom_version;
109     uint8_t    bt_hci_chip_id;
110     LE_STREAM_TO_UINT8(rom_version, p_buf);
111     HCI_PRINT_INFO1("hci_tp_config: rom_version 0x%02x", rom_version);
112     bt_hci_chip_id = rom_version + 1;
113     hci_board_debug("%s: rom_version 0x%04x, bt_hci_chip_id 0x%04x\n", __FUNCTION__, rom_version, bt_hci_chip_id);
114 
115     ret = hci_rtk_find_patch(bt_hci_chip_id);
116     if(ret == false)
117     {
118         hci_board_debug("\r\n%s: error operate\r\n",__FUNCTION__);
119         return HCI_TP_CHECK_ERROR;
120     }
121 
122     return HCI_TP_CHECK_OK;
123 }
124 
hci_tp_read_thermal(void)125 uint8_t hci_tp_read_thermal(void)
126 {
127     uint8_t *p_cmd;
128     uint8_t *p;
129 
130     HCI_PRINT_TRACE0("hci_tp_read_thermal");
131 
132     if (rltk_wlan_is_mp())
133     {
134         p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 4);
135             if (p_cmd != NULL)
136             {
137                 p = p_cmd;
138                     LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
139                     LE_UINT16_TO_STREAM(p, HCI_VSC_READ_THERMAL);
140                     LE_UINT8_TO_STREAM(p, 0); /* length */
141 
142                     hci_adapter_send(p_cmd, p - p_cmd);
143             }
144             else
145             {
146                 return HCI_TP_CONFIG_FAIL;
147             }
148         return HCI_TP_CHECK_OK;
149     }
150     else
151     {
152         return HCI_TP_NOT_SEND;
153     }
154 }
155 
freq_cmp(const void * a,const void * b)156 static int freq_cmp(const void *a, const void *b)
157 {
158 	int _a = *(int *) a;
159 	int _b = *(int *) b;
160 
161 	if (_a == 0)
162 		return 1;
163 	if (_b == 0)
164 		return -1;
165 	return _a - _b;
166 }
167 
hci_thermal_check(uint8_t len,uint8_t * p_buf)168 uint8_t hci_thermal_check(uint8_t len, uint8_t *p_buf)
169 {
170     (void)len;
171     (void)p_buf;
172     uint8_t    thermal;
173     LE_STREAM_TO_UINT8(thermal, p_buf);
174 
175     if (vendor_flow > 2)   /* fortime */
176     {
177         if(!CHECK_SW(EFUSE_SW_DRIVER_DEBUG_LOG))
178         {
179             hci_board_debug("%s: thermal_check 0x%02x\n",__FUNCTION__,thermal);
180         }
181 		qsort(orignal_thermal, 3, sizeof(uint8_t), freq_cmp);
182         hci_board_debug("\n\rthermal_check OK orignal_thermal[1] = %x\n", orignal_thermal[1]);
183 
184 		thermal = orignal_thermal[1]&0x3F;
185 		hci_board_debug("\n\rthermal_check OK thermal = %x\n", thermal);
186 		hci_tp_phy_efuse[7]=thermal;
187         vendor_flow = 0;
188         return HCI_TP_CHECK_OK;
189     }
190     else
191     {
192         if(!CHECK_SW(EFUSE_SW_DRIVER_DEBUG_LOG))
193         {
194             hci_board_debug("%s: thermal_check 0x%02x, time %x\n",__FUNCTION__,thermal, vendor_flow);
195         }
196         orignal_thermal[vendor_flow]=thermal;
197         vendor_flow++;
198         return HCI_TP_CHECK_AGAIN;
199     }
200 }
201 //==========================patch==========================
202 
203 typedef struct
204 {
205     uint8_t            *fw_buf;
206     uint8_t            *config_buf;
207     uint8_t             patch_frag_cnt;
208     uint8_t             patch_frag_idx;
209     uint8_t             patch_frag_len;
210     uint8_t             patch_frag_tail;
211     uint16_t            fw_len;
212     uint16_t            config_len;
213     uint32_t            baudrate;
214 }T_HCI_PATCH;
215 
216 T_HCI_PATCH hci_patch_info;
217 
218 #define PATCH_FRAGMENT_MAX_SIZE         252
hci_set_patch(uint8_t * fw_addr,uint32_t fw_len,uint8_t * fw_config_addr,uint32_t fw_config_len,uint32_t baudrate)219 bool hci_set_patch(uint8_t *fw_addr,uint32_t fw_len, uint8_t *fw_config_addr, uint32_t
220         fw_config_len, uint32_t baudrate)
221 {
222     T_HCI_PATCH *p_hci_patch = &hci_patch_info;
223     uint32_t svn_version, coex_version, lmp_subversion;
224 
225     p_hci_patch->fw_len = fw_len;
226     p_hci_patch->fw_buf = fw_addr;
227     p_hci_patch->config_buf = fw_config_addr;
228     p_hci_patch->config_len = fw_config_len;
229     p_hci_patch->patch_frag_idx = 0;
230     p_hci_patch->baudrate = baudrate;
231     //p_hci_patch->config_len = 0;
232     LE_ARRAY_TO_UINT32(svn_version, (p_hci_patch->fw_buf+p_hci_patch->fw_len-8));
233     LE_ARRAY_TO_UINT32(coex_version, (p_hci_patch->fw_buf+p_hci_patch->fw_len-12));
234     LE_ARRAY_TO_UINT32(lmp_subversion, (p_hci_patch->fw_buf+p_hci_patch->fw_len-4));
235     p_hci_patch->patch_frag_cnt  = (p_hci_patch->fw_len + p_hci_patch->config_len) / PATCH_FRAGMENT_MAX_SIZE;
236     p_hci_patch->patch_frag_tail = (p_hci_patch->fw_len + p_hci_patch->config_len) % PATCH_FRAGMENT_MAX_SIZE;
237 
238     if (p_hci_patch->patch_frag_tail)
239     {
240         p_hci_patch->patch_frag_cnt += 1;
241     }
242     else
243     {
244         p_hci_patch->patch_frag_tail = PATCH_FRAGMENT_MAX_SIZE;
245     }
246     HCI_PRINT_INFO3("hci_rtk_load_patch:svn %d patch frag count %u, tail len %u",svn_version,
247                     p_hci_patch->patch_frag_cnt, p_hci_patch->patch_frag_tail);
248 
249 
250     HCI_PRINT_INFO3("BT patch:svn %d coex svn_version: %x LMP VERSION:%x\n",(int)svn_version, (unsigned int)coex_version,(unsigned int)lmp_subversion);
251     if (rltk_wlan_is_mp())
252     {
253         hci_board_debug("BT patch:svn %d coex svn_version: %x LMP VERSION:%x\n",(int)svn_version, (unsigned int)coex_version,(unsigned int)lmp_subversion);
254     }
255     (void)coex_version;
256     (void)lmp_subversion;
257     return true;
258 }
259 
hci_tp_download_patch(void)260 uint8_t hci_tp_download_patch(void)
261 {
262     uint8_t  *p_cmd;
263     uint8_t  *p;
264     uint8_t  *p_frag;
265     uint16_t  sent_len;
266     T_HCI_PATCH *p_hci_rtk = &hci_patch_info;
267 
268     if (p_hci_rtk->patch_frag_idx < p_hci_rtk->patch_frag_cnt)
269     {
270         if (p_hci_rtk->patch_frag_idx == p_hci_rtk->patch_frag_cnt - 1)
271         {
272             HCI_PRINT_TRACE0("hci_tp_download_patch: send last frag");
273             //hci_board_debug("hci_tp_download_patch: send last frag\n");
274 
275             p_hci_rtk->patch_frag_idx |= 0x80;
276             p_hci_rtk->patch_frag_len  = p_hci_rtk->patch_frag_tail;
277         }
278         else
279         {
280             p_hci_rtk->patch_frag_len = PATCH_FRAGMENT_MAX_SIZE;
281         }
282     }
283 
284     //hci_board_debug("hci_tp_download_patch: frag index %d, len %d\n",
285      //         p_hci_rtk->patch_frag_idx, p_hci_rtk->patch_frag_len);
286     HCI_PRINT_TRACE2("hci_tp_download_patch: frag index %d, len %d",
287                      p_hci_rtk->patch_frag_idx, p_hci_rtk->patch_frag_len);
288 
289     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, HCI_CMD_HDR_LEN + 1 + p_hci_rtk->patch_frag_len);
290     if (p_cmd != NULL)
291     {
292         p = p_cmd;
293         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
294         LE_UINT16_TO_STREAM(p, HCI_VSC_DOWNLOAD_PATCH);
295         LE_UINT8_TO_STREAM(p, 1 + p_hci_rtk->patch_frag_len);  /* length */
296         LE_UINT8_TO_STREAM(p, p_hci_rtk->patch_frag_idx);  /* frag index */
297 
298         sent_len = (p_hci_rtk->patch_frag_idx & 0x7F) * PATCH_FRAGMENT_MAX_SIZE;
299 
300         if (sent_len >= p_hci_rtk->fw_len)    /* config patch domain */
301         {
302             p_frag = p_hci_rtk->config_buf + sent_len -p_hci_rtk->fw_len;
303             memcpy(p, p_frag, p_hci_rtk->patch_frag_len);
304         }
305         else if (sent_len + p_hci_rtk->patch_frag_len <= p_hci_rtk->fw_len) /* fw patch domain */
306         {
307             p_frag = p_hci_rtk->fw_buf + sent_len;
308             memcpy(p, p_frag, p_hci_rtk->patch_frag_len);
309         }
310         else    /* accross fw and config patch domains */
311         {
312             p_frag = p_hci_rtk->fw_buf + sent_len;
313             memcpy(p, p_frag, p_hci_rtk->fw_len - sent_len);
314             p += p_hci_rtk->fw_len - sent_len;
315             memcpy(p, p_hci_rtk->config_buf, p_hci_rtk->patch_frag_len + sent_len - p_hci_rtk->fw_len);
316         }
317 
318         p_hci_rtk->patch_frag_idx++;
319         hci_adapter_send(p_cmd, HCI_CMD_HDR_LEN + 1 + p_hci_rtk->patch_frag_len);
320         //hci_tp_send(p_cmd, HCI_CMD_HDR_LEN + 1 + p_hci_rtk->patch_frag_len, hci_rtk_tx_cb);
321     }
322     else
323     {
324         hci_board_debug("%s:p_cmd is NULL \n", __FUNCTION__);
325         return HCI_TP_CONFIG_FAIL;
326     }
327     return HCI_TP_CHECK_OK;
328 }
329 
hci_download_patch_check(uint8_t len,uint8_t * p_buf)330 uint8_t hci_download_patch_check(uint8_t len, uint8_t *p_buf)
331 {
332     (void)len;
333     uint8_t index;
334     LE_STREAM_TO_UINT8(index, p_buf);
335     T_HCI_PATCH *p_hci_rtk = &hci_patch_info;
336     if (index & 0x80)   /* receive the last fragment completed evt */
337     {
338         HCI_PRINT_INFO0("Download patch completely\n");
339         //hci_board_debug("Download patch completely\n");
340         os_mem_free(p_hci_rtk->fw_buf);
341         os_mem_free(p_hci_rtk->config_buf);
342         return HCI_TP_CHECK_OK;
343     }
344     else
345     {
346         return HCI_TP_CHECK_AGAIN;
347     }
348 }
349 
hci_tp_set_controller_baudrate(void)350 uint8_t hci_tp_set_controller_baudrate(void)
351 {
352     uint8_t *p_cmd;
353     uint8_t *p;
354     T_HCI_PATCH *p_hci_rtk = &hci_patch_info;
355 
356     HCI_PRINT_TRACE1("hci_tp_set_controller_baudrate: baudrate 0x%08x", p_hci_rtk->baudrate);
357     //hci_board_debug("hci_tp_set_controller_baudrate: baudrate 0x%08x\n", p_hci_rtk->baudrate);
358 
359     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, HCI_CMD_HDR_LEN + 4);
360     if (p_cmd != NULL)
361     {
362         p = p_cmd;
363         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
364         LE_UINT16_TO_STREAM(p, HCI_VSC_UPDATE_BAUDRATE);
365         LE_UINT8_TO_STREAM(p, 4);   /* length */
366         LE_UINT32_TO_STREAM(p, p_hci_rtk->baudrate);
367         hci_adapter_send(p_cmd, p - p_cmd);
368         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
369     }
370     else
371     {
372         hci_board_debug("%s:p_cmd is NULL \n", __FUNCTION__);
373         return HCI_TP_CONFIG_FAIL;
374     }
375     return HCI_TP_CHECK_OK;
376 }
377 
hci_rtk_convert_buadrate(uint32_t bt_baudrate,uint32_t * uart_baudrate)378 static void hci_rtk_convert_buadrate(uint32_t bt_baudrate, uint32_t *uart_baudrate)
379 {
380     uint8_t i;
381 
382     *uart_baudrate = 115200;
383 extern const BAUDRATE_MAP baudrates[];
384 extern unsigned int baudrates_length;
385 
386     for (i = 0; i < baudrates_length; i++)
387     {
388         if (baudrates[i].bt_baudrate == bt_baudrate)
389         {
390             *uart_baudrate = baudrates[i].uart_baudrate;
391             return;
392         }
393     }
394 
395     HCI_PRINT_TRACE0("hci_rtk_convert_buadrate: use default baudrate[115200]");
396     return;
397 }
398 
hci_set_baudrate_check(uint8_t len,uint8_t * p_buf)399 uint8_t hci_set_baudrate_check(uint8_t len, uint8_t *p_buf)
400 {
401     (void)len;
402     (void)p_buf;
403     uint32_t uart_baudrate;
404     T_HCI_PATCH *p_hci_rtk = &hci_patch_info;
405     hci_rtk_convert_buadrate(p_hci_rtk->baudrate, &uart_baudrate);
406     //hci_board_debug("hci_tp_set_controller_baudrate: baudrate %d\n", uart_baudrate);
407     hci_uart_set_baudrate(uart_baudrate);
408     os_delay(50);
409     return HCI_TP_CHECK_OK;
410 }
411 //==================================IQK=======LOK=======
hci_tp_rf_radio_ver(uint8_t offset,uint16_t value)412 uint8_t hci_tp_rf_radio_ver(uint8_t offset, uint16_t value)
413 {
414     uint8_t *p_cmd;
415     uint8_t *p;
416 
417     HCI_PRINT_TRACE0("hci_tp_rf_radio_ver");
418     hci_board_debug("hci_tp_rf_radio_ver\n");
419 
420     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 8);
421     if (p_cmd != NULL)
422     {
423         p = p_cmd;
424         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
425         LE_UINT16_TO_STREAM(p, HCI_VENDOR_RF_RADIO_REG_WRITE);
426         LE_UINT8_TO_STREAM(p, 4); /* length */
427         LE_UINT8_TO_STREAM(p, offset); /* offset		*/
428         LE_UINT16_TO_STREAM(p, value); /* value */
429         LE_UINT8_TO_STREAM(p, 0); /*  */
430 
431         hci_adapter_send(p_cmd, p - p_cmd);
432         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
433     }
434     else
435     {
436         return HCI_TP_CONFIG_FAIL;
437     }
438     return HCI_TP_CHECK_OK;
439 }
440 
441 
442 // after IQK done, reset iqk_type to let next bt init do bt_check_iqk
reset_iqk_type(void)443 void reset_iqk_type(void) {
444 	iqk_type = 0xff;
445 }
446 
hci_tp_rf_radio_ver_flow(void)447 uint8_t hci_tp_rf_radio_ver_flow(void)
448 {
449 #define NONEEDSTARTIQK  0x02
450     if(iqk_type != NONEEDSTARTIQK)
451     {
452         if(bt_check_iqk() == true)
453         {
454                 //hci_board_debug("we have iqk value:  DUMP,\r\n");
455                 return HCI_TP_NOT_SEND;
456         }
457         hci_board_debug("we need start iqk\r\n");
458         iqk_type = NONEEDSTARTIQK;
459     }
460 
461     if(vendor_flow == 0)
462     {
463          hci_tp_rf_radio_ver(0x00, CALI_IQK_RF_STEP0);
464     }
465     else if(vendor_flow == 1)
466     {
467         hci_tp_rf_radio_ver(0x01, CALI_IQK_RF_STEP1);
468     }
469 	else if(vendor_flow == 2)
470     {
471 		hci_tp_rf_radio_ver(0x02, CALI_IQK_RF_STEP2);
472 	}
473 	else if(vendor_flow == 3)
474 	{
475 		hci_tp_rf_radio_ver(0x3f, CALI_IQK_RF_STEP3F);
476 	}
477 	else
478     {
479         hci_board_debug("IQK error\n");
480     }
481     return HCI_TP_CHECK_OK;
482 }
hci_write_rf_check(uint8_t len,uint8_t * p_buf)483 uint8_t hci_write_rf_check(uint8_t len, uint8_t *p_buf)
484 {
485     (void)len;
486     (void)p_buf;
487     if (vendor_flow >= 3)   /* receive the last fragment completed evt */
488     {
489         if(hci_start_iqk()== false)
490         {
491                 vendor_flow = 0;
492                 return HCI_TP_CONFIG_FAIL;
493         }
494         hci_board_debug("\n\rIQK OK\n");
495         vendor_flow = 0;
496         return HCI_TP_CHECK_OK;
497     }
498     else
499     {
500         hci_board_debug("continue add  %x\n", vendor_flow);
501         vendor_flow++;
502         return HCI_TP_CHECK_AGAIN;
503     }
504 }
505 
hci_tp_write_efuse_iqk(void)506 uint8_t hci_tp_write_efuse_iqk(void)
507 {
508     uint8_t *p_cmd;
509     uint8_t *p;
510 
511     HCI_PRINT_TRACE0("hci_tp_write_efuse_iqk");
512 
513     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 23);
514     if (p_cmd != NULL)
515     {
516         p = p_cmd;
517         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
518         LE_UINT16_TO_STREAM(p, HCI_VSC_VENDOR_IQK);
519         LE_UINT8_TO_STREAM(p, 19); /* length */
520 
521         memcpy(p, hci_tp_phy_efuse, 19);
522         p+=19;
523         hci_adapter_send(p_cmd, p - p_cmd);
524         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
525         return HCI_TP_CHECK_OK;
526     }
527     else
528     {
529         return HCI_TP_CONFIG_FAIL;
530     }
531 }
532 //=========================================================
hci_tp_hci_reset(void)533 uint8_t hci_tp_hci_reset(void)
534 {
535     uint8_t *p_cmd;
536     uint8_t *p;
537     HCI_PRINT_TRACE0("hci_reset");
538     //hci_board_debug("hci_reset\n");
539     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 4);
540     if (p_cmd != NULL)
541     {
542         p = p_cmd;
543         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
544         LE_UINT16_TO_STREAM(p, HCI_HCI_RESET);
545         LE_UINT8_TO_STREAM(p, 0); /* length */
546         hci_adapter_send(p_cmd, p - p_cmd);
547         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
548     }
549     else
550     {
551         return HCI_TP_CONFIG_FAIL;
552     }
553     return HCI_TP_CHECK_OK;
554 }
555 
556 HCI_PROCESS_TABLE hci_process_table[] ={
557 #ifdef HCI_START_IQK
558     {HCI_VENDOR_RF_RADIO_REG_WRITE, hci_tp_rf_radio_ver_flow, hci_write_rf_check},
559 #endif
560     //pre donload patch
561     {HCI_READ_LOCAL_VERSION_INFO,hci_tp_read_local_ver, hci_read_local_version_check},
562     {HCI_VSC_READ_ROM_VERSION,hci_tp_read_rom_ver, hci_read_rom_check},
563 
564     //download patch
565     {HCI_VSC_UPDATE_BAUDRATE,hci_tp_set_controller_baudrate, hci_set_baudrate_check},
566     {HCI_VSC_DOWNLOAD_PATCH,hci_tp_download_patch, hci_download_patch_check},
567 #ifdef FT_MODE
568     {HCI_VSC_READ_THERMAL,hci_tp_read_thermal, hci_thermal_check},
569 #endif
570 
571 #ifdef HCI_WRITE_IQK
572     {HCI_VSC_VENDOR_IQK,hci_tp_write_efuse_iqk, NULL},
573 #endif
574     {HCI_HCI_RESET,hci_tp_hci_reset, NULL},
575 };
576 uint8_t hci_total_step = sizeof(hci_process_table)/sizeof(HCI_PROCESS_TABLE);
577 
hci_tp_tx_test_cmd(void)578 uint8_t hci_tp_tx_test_cmd(void)
579 {
580     uint8_t *p_cmd;
581     uint8_t *p;
582 
583     //HCI_PRINT_TRACE0("hci_tp_read_local_ver");
584     //
585 #define HCI_LE_TRANSMIT_TEST 0x201e
586     hci_board_debug("hci_tp_tx_test_cmd 2402, 0xFF, 0x00\n");
587 
588     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 7);
589     if (p_cmd != NULL)
590     {
591         p = p_cmd;
592         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
593         LE_UINT16_TO_STREAM(p, HCI_LE_TRANSMIT_TEST);
594         LE_UINT8_TO_STREAM(p, 3);
595         LE_UINT8_TO_STREAM(p, 0);//TX_CHANNEL
596         LE_UINT8_TO_STREAM(p, 0xff);//length_of_test_data
597         LE_UINT8_TO_STREAM(p, 0);//packet_payload
598         hci_adapter_send(p_cmd, p - p_cmd);
599         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
600     }
601     else
602     {
603          return HCI_TP_CONFIG_FAIL;
604     }
605     return HCI_TP_CHECK_OK;
606 }
607 
hci_tp_rx_test_cmd(void)608 uint8_t hci_tp_rx_test_cmd(void)
609 {
610     uint8_t *p_cmd;
611     uint8_t *p;
612 
613     //HCI_PRINT_TRACE0("hci_tp_read_local_ver");
614     //
615 #define HCI_LE_RECEIVE_TEST 0x201d
616     hci_board_debug("hci_tp_rx_test_cmd 2402\n");
617     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 6);
618     if (p_cmd != NULL)
619     {
620         p = p_cmd;
621         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
622         LE_UINT16_TO_STREAM(p, HCI_LE_RECEIVE_TEST);
623         LE_UINT8_TO_STREAM(p, 1);
624         LE_UINT8_TO_STREAM(p, 0);//TX_CHANNEL
625         hci_adapter_send(p_cmd, p - p_cmd);
626         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
627 
628     }
629     else
630     {
631         return HCI_TP_CONFIG_FAIL;
632     }
633      return HCI_TP_CHECK_OK;
634 }
635 
hci_tp_test_end_cmd(void)636 uint8_t hci_tp_test_end_cmd(void)
637 {
638     uint8_t *p_cmd;
639     uint8_t *p;
640 
641 #define HCI_LE_TEST_END 0x201f
642     hci_board_debug("hci_tp_rx_test_cmd 2402\n");
643     p_cmd = os_mem_zalloc(RAM_TYPE_DATA_ON, 6);
644     if (p_cmd != NULL)
645     {
646         p = p_cmd;
647         LE_UINT8_TO_STREAM(p, HCI_CMD_PKT);
648         LE_UINT16_TO_STREAM(p, HCI_LE_TEST_END);
649         LE_UINT8_TO_STREAM(p, 0);
650 
651         hci_adapter_send(p_cmd, p - p_cmd);
652         //hci_tp_send(p_cmd, p - p_cmd, hci_rtk_tx_cb);
653     }
654     else
655     {
656        return HCI_TP_CONFIG_FAIL;
657     }
658      return HCI_TP_CHECK_OK;
659 }
660