Files

215 lines
6.1 KiB
C

/*================================================================
Copyright (c) 2022, Quectel Wireless Solutions Co., Ltd. All rights reserved.
Quectel Wireless Solutions Proprietary and Confidential.
=================================================================*/
#include "quec_cust_feature.h"
#ifdef QUEC_BT_PRODUCIBILITY
#include "ql_bt_drive.h"
extern quec_bt_open_status quec_bt_open_status_get_cb;
extern quec_bt_scan_status quec_bt_scan_get_cb ;
extern quec_bt_rssi_status quec_bt_rssi_get_cb;
extern le_scan_event_handle_t le_scan_event_handle;
extern BOOL quec_bt_INQUIRY;
ql_bt_event_handlers_t ql_bt_event_handlers_table[] = {
{QL_BTTASK_IND_TYPE_COMMON, NULL},
{QL_BTTASK_IND_TYPE_ACL, NULL},
{QL_BTTASK_IND_TYPE_SCO, NULL},
{QL_BTTASK_IND_TYPE_A2DP, NULL},
{QL_BTTASK_IND_TYPE_AVRCP, NULL},
{QL_BTTASK_IND_TYPE_HFP, NULL},
{QL_BTTASK_IND_TYPE_OBEX, NULL},
{QL_BTTASK_IND_TYPE_SPP, NULL},
{QL_BTTASK_IND_TYPE_LE, NULL},
{QL_BTTASK_IND_TYPE_A2DP, NULL},
{QL_BTTASK_IND_TYPE_AVRCP, NULL},
{QL_BTTASK_IND_TYPE_HFP, NULL},
{QL_BTTASK_IND_TYPE_OBEX, NULL},
{QL_BTTASK_IND_TYPE_SPP, NULL},
{QL_BTTASK_IND_TYPE_LE, NULL},
{QL_BTTASK_IND_TYPE_A2DP_SINK, NULL},
{QL_BTTASK_IND_TYPE_HFP_HF, NULL},
{QL_BTTASK_IND_TYPE_HID, NULL},
{QL_BTTASK_IND_TYPE_PBAP, NULL},
{QL_BTTASK_IND_TYPE_MAP, NULL},
{QL_BTTASK_IND_TYPE_FTP, NULL},
};
ql_bt_err_t ql_bt_register_event_handler(ql_bt_event_type_e event, ql_bt_event_callback_t handler_func)
{
ql_bt_err_t ret = QL_BT_OK;
int counter = 0;
ql_bt_log("ql_bt_event_handlers_table count %d", COUNT_OF(ql_bt_event_handlers_table));
for(counter = 0; counter < COUNT_OF(ql_bt_event_handlers_table); counter++)
{
if(ql_bt_event_handlers_table[counter].ql_bt_event_type == event)
{
ql_bt_log("ql_bt_register_event_handler: event %d handler %p", event, handler_func);
if(handler_func != NULL)
{
ql_bt_event_handlers_table[counter].ql_bt_event_cb_func = handler_func;
}
else
{
ql_bt_log("event callback function can not be NULL");
}
break;
}
}
return ret;
}
ql_bt_err_t ql_bt_unregister_event_handler(ql_bt_event_type_e event)
{
ql_bt_err_t ret = QL_BT_OK;
int counter = 0;
ql_bt_log("ql_bt_event_handlers_table count %d", COUNT_OF(ql_bt_event_handlers_table));
for(counter = 0; counter < COUNT_OF(ql_bt_event_handlers_table); counter++)
{
if(ql_bt_event_handlers_table[counter].ql_bt_event_type == event)
{
ql_bt_log("ql_bt_register_event_handler: event %d handler %p", event, ql_bt_event_handlers_table[counter].ql_bt_event_cb_func);
if(ql_bt_event_handlers_table[counter].ql_bt_event_cb_func != NULL)
{
ql_bt_event_handlers_table[counter].ql_bt_event_cb_func = NULL;
}
break;
}
}
return ret;
}
ql_bt_err_t ql_bt_get_event_handler_cb(ql_bt_event_type_e event, ql_bt_event_callback_t *handler_func)
{
ql_bt_err_t ret = QL_BT_OK;
int counter = 0;
ql_bt_log("ql_bt_event_handlers_table count %d", COUNT_OF(ql_bt_event_handlers_table));
for(counter = 0; counter < COUNT_OF(ql_bt_event_handlers_table); counter++)
{
if(ql_bt_event_handlers_table[counter].ql_bt_event_type == event)
{
ql_bt_log("ql_bt_register_event_handler: event %d handler %p", event, ql_bt_event_handlers_table[counter].ql_bt_event_cb_func);
if(handler_func != NULL)
{
*handler_func = ql_bt_event_handlers_table[counter].ql_bt_event_cb_func;
}
else
{
ql_bt_log("handler_func can not be NULL");
}
break;
}
}
return ret;
}
void ql_bt_mgr_event_handle(struct bt_task_event * msg)
{
ql_bt_event_callback_t handler_func= NULL;
ql_bt_log("ql_bt_mgr_event_handle: event %d handler %p", msg->event_type, handler_func);
switch (msg->event_type)
{
case QL_BTTASK_IND_TYPE_COMMON:
{
if(quec_bt_scan_get_cb != NULL) {
switch(msg->event_id)
{
case BTTASK_IND_INQUIRY_RESULT:
{
struct bt_event_inquiry *inquiry =(struct bt_event_inquiry *)msg->payload;
quec_bt_scan_get_cb(inquiry,1);
return;
}
case BTTASK_IND_INQUIRY_COMPLETE:
{
quec_bt_scan_get_cb(NULL,0);
quec_bt_INQUIRY= FALSE;
quec_bt_scan_get_cb=NULL;
return;
}
}
}
if(quec_bt_open_status_get_cb != NULL){
switch(msg->event_id)
{
case BTTASK_IND_POWERUP_COMPLETE:
{
quec_bt_open_status_get_cb(0,NULL);
return;
}
case BTTASK_IND_POWERUP_FAILED:
{
quec_bt_open_status_get_cb(1,NULL);
return;
}
case BTTASK_IND_BTFIRMWARE_ASSERT:
{
quec_bt_open_status_get_cb(2,NULL);
return;
}
case BTTASK_IND_SHUTDOWN_COMPLETE:
{
quec_bt_open_status_get_cb(3,NULL);
return;
}
}
}
if(quec_bt_rssi_get_cb != NULL){
switch(msg->event_id)
{
case BTTASK_IND_RSSI:
{
signed char *value_rssi = (signed char *)msg->payload;
quec_bt_rssi_get_cb(*value_rssi);
return;
}
}
}
break ;
}
case QL_BTTASK_IND_TYPE_LE:
{
if(le_scan_event_handle != NULL){
switch(msg->event_id)
{
case BTTASK_IND_LE_SCAN_EVENT:
{
struct bt_event_le_scan_event *scan = (struct bt_event_le_scan_event *)msg->payload;
le_scan_event_handle(scan);
return;
}
}
}
break ;
}
}
ql_bt_get_event_handler_cb((ql_bt_event_type_e)msg->event_type, &handler_func);
if(handler_func == NULL) {
return;
}else{
handler_func(msg->event_id, msg->payload);
}
}
#endif