1 /******************************************************************************
2  *
3  *  Copyright (C) 2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This is the main implementation file for the BTA Java I/F
22  *
23  ******************************************************************************/
24 
25 #include "bta/bta_api.h"
26 #include "bta/bta_sys.h"
27 #include "bta/bta_jv_api.h"
28 #include "bta_jv_int.h"
29 #include "common/bt_target.h"
30 
31 #if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE)
32 /*****************************************************************************
33 ** Constants and types
34 *****************************************************************************/
35 
36 #if BTA_DYNAMIC_MEMORY == FALSE
37 tBTA_JV_CB bta_jv_cb;
38 #else
39 tBTA_JV_CB *bta_jv_cb_ptr;
40 #endif
41 
42 /* state machine action enumeration list */
43 #define BTA_JV_NUM_ACTIONS  (BTA_JV_MAX_INT_EVT & 0x00ff)
44 
45 /* type for action functions */
46 typedef void (*tBTA_JV_ACTION)(tBTA_JV_MSG *p_data);
47 
48 /* action function list */
49 const tBTA_JV_ACTION bta_jv_action[] = {
50     bta_jv_enable,                  /* BTA_JV_API_ENABLE_EVT */
51     bta_jv_disable,                 /* BTA_JV_API_DISABLE_EVT */
52     bta_jv_get_channel_id,          /* BTA_JV_API_GET_CHANNEL_EVT */
53     bta_jv_free_scn,                /* BTA_JV_API_FREE_SCN_EVT */
54     bta_jv_start_discovery,         /* BTA_JV_API_START_DISCOVERY_EVT */
55     bta_jv_create_record,           /* BTA_JV_API_CREATE_RECORD_EVT */
56     bta_jv_delete_record,           /* BTA_JV_API_DELETE_RECORD_EVT */
57 #if BTA_JV_L2CAP_INCLUDED
58     bta_jv_l2cap_connect,           /* BTA_JV_API_L2CAP_CONNECT_EVT */
59     bta_jv_l2cap_close,             /* BTA_JV_API_L2CAP_CLOSE_EVT */
60     bta_jv_l2cap_start_server,      /* BTA_JV_API_L2CAP_START_SERVER_EVT */
61     bta_jv_l2cap_stop_server,       /* BTA_JV_API_L2CAP_STOP_SERVER_EVT */
62     bta_jv_l2cap_read,              /* BTA_JV_API_L2CAP_READ_EVT */
63     bta_jv_l2cap_write,             /* BTA_JV_API_L2CAP_WRITE_EVT */
64 #endif /* BTA_JV_L2CAP_INCLUDED */
65     bta_jv_rfcomm_connect,          /* BTA_JV_API_RFCOMM_CONNECT_EVT */
66     bta_jv_rfcomm_close,            /* BTA_JV_API_RFCOMM_CLOSE_EVT */
67     bta_jv_rfcomm_start_server,     /* BTA_JV_API_RFCOMM_START_SERVER_EVT */
68     bta_jv_rfcomm_stop_server,      /* BTA_JV_API_RFCOMM_STOP_SERVER_EVT */
69     bta_jv_rfcomm_read,             /* BTA_JV_API_RFCOMM_READ_EVT */
70     bta_jv_rfcomm_write,            /* BTA_JV_API_RFCOMM_WRITE_EVT */
71     bta_jv_rfcomm_flow_control,     /* BTA_JV_API_RFCOMM_FLOW_CONTROL_EVT */
72     bta_jv_set_pm_profile,          /* BTA_JV_API_SET_PM_PROFILE_EVT */
73     bta_jv_change_pm_state,         /* BTA_JV_API_PM_STATE_CHANGE_EVT */
74 #if BTA_JV_L2CAP_INCLUDED
75     bta_jv_l2cap_connect_le,        /* BTA_JV_API_L2CAP_CONNECT_LE_EVT */
76     bta_jv_l2cap_start_server_le,   /* BTA_JV_API_L2CAP_START_SERVER_LE_EVT */
77     bta_jv_l2cap_stop_server_le,    /* BTA_JV_API_L2CAP_STOP_SERVER_LE_EVT */
78     bta_jv_l2cap_write_fixed,       /* BTA_JV_API_L2CAP_WRITE_FIXED_EVT */
79     bta_jv_l2cap_close_fixed,       /*  BTA_JV_API_L2CAP_CLOSE_FIXED_EVT */
80 #endif /* BTA_JV_L2CAP_INCLUDED */
81 };
82 
83 /*******************************************************************************
84 **
85 ** Function         bta_jv_sm_execute
86 **
87 ** Description      State machine event handling function for JV
88 **
89 **
90 ** Returns          void
91 **
92 *******************************************************************************/
bta_jv_sm_execute(BT_HDR * p_msg)93 BOOLEAN bta_jv_sm_execute(BT_HDR *p_msg)
94 {
95     BOOLEAN ret = FALSE;
96     UINT16 action = (p_msg->event & 0x00ff);
97     /* execute action functions */
98 
99     if (action < BTA_JV_NUM_ACTIONS) {
100         (*bta_jv_action[action])((tBTA_JV_MSG *)p_msg);
101         ret = TRUE;
102     }
103 
104     return (ret);
105 }
106 
107 #endif  ///defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE
108