blob: 78c6ed38adaf14af84c8e121b07b218024f6534b [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 2007-2012 Broadcom Corporation
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 *
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#ifndef UIPC_H
19#define UIPC_H
20
Hansong Zhangbe754da2018-01-19 12:23:57 -080021#include <mutex>
22
Myles Watson911d1ae2016-11-28 16:44:40 -080023#define UIPC_CH_ID_AV_CTRL 0
The Android Open Source Project5738f832012-12-12 16:00:35 -080024#define UIPC_CH_ID_AV_AUDIO 1
Myles Watson911d1ae2016-11-28 16:44:40 -080025#define UIPC_CH_NUM 2
The Android Open Source Project5738f832012-12-12 16:00:35 -080026
Myles Watson911d1ae2016-11-28 16:44:40 -080027#define UIPC_CH_ID_ALL 3 /* used to address all the ch id at once */
The Android Open Source Project5738f832012-12-12 16:00:35 -080028
29#define DEFAULT_READ_POLL_TMO_MS 100
30
Marie Janssend19e0782016-07-15 12:48:27 -070031typedef uint8_t tUIPC_CH_ID;
The Android Open Source Project5738f832012-12-12 16:00:35 -080032
33/* Events generated */
34typedef enum {
Myles Watson911d1ae2016-11-28 16:44:40 -080035 UIPC_OPEN_EVT = 0x0001,
36 UIPC_CLOSE_EVT = 0x0002,
37 UIPC_RX_DATA_EVT = 0x0004,
38 UIPC_RX_DATA_READY_EVT = 0x0008,
39 UIPC_TX_DATA_READY_EVT = 0x0010
The Android Open Source Project5738f832012-12-12 16:00:35 -080040} tUIPC_EVENT;
41
42/*
43 * UIPC IOCTL Requests
44 */
45
Myles Watson911d1ae2016-11-28 16:44:40 -080046#define UIPC_REQ_RX_FLUSH 1
47#define UIPC_REG_CBACK 2
48#define UIPC_REG_REMOVE_ACTIVE_READSET 3
49#define UIPC_SET_READ_POLL_TMO 4
The Android Open Source Project5738f832012-12-12 16:00:35 -080050
Myles Watson911d1ae2016-11-28 16:44:40 -080051typedef void(tUIPC_RCV_CBACK)(
52 tUIPC_CH_ID ch_id,
53 tUIPC_EVENT event); /* points to BT_HDR which describes event type and
54 length of data; len contains the number of bytes of
55 entire message (sizeof(BT_HDR) + offset + size of
56 data) */
The Android Open Source Project5738f832012-12-12 16:00:35 -080057
The Android Open Source Project5738f832012-12-12 16:00:35 -080058const char* dump_uipc_event(tUIPC_EVENT event);
59
Jakub Pawlowski4653f212018-03-01 16:23:58 -080060typedef struct {
61 int srvfd;
62 int fd;
63 int read_poll_tmo_ms;
64 int task_evt_flags; /* event flags pending to be processed in read task */
65 tUIPC_RCV_CBACK* cback;
66} tUIPC_CHAN;
67
68struct tUIPC_STATE {
69 pthread_t tid; /* main thread id */
70 int running;
71 std::recursive_mutex mutex;
72
73 fd_set active_set;
74 fd_set read_set;
75 int max_fd;
76 int signal_fds[2];
77
78 tUIPC_CHAN ch[UIPC_CH_NUM];
79};
80
Hansong Zhangf88552c2018-02-01 18:02:53 -080081/**
82 * Initialize UIPC module
Myles Watsonee96a3c2016-11-23 14:49:54 -080083 *
Hansong Zhangf88552c2018-02-01 18:02:53 -080084 * @param user User ID who uses UIPC
85 */
Jakub Pawlowski4653f212018-03-01 16:23:58 -080086std::unique_ptr<tUIPC_STATE> UIPC_Init();
The Android Open Source Project5738f832012-12-12 16:00:35 -080087
Hansong Zhangf88552c2018-02-01 18:02:53 -080088/**
89 * Open a UIPC channel
Myles Watsonee96a3c2016-11-23 14:49:54 -080090 *
Hansong Zhangf88552c2018-02-01 18:02:53 -080091 * @param ch_id Channel ID
92 * @param p_cback Callback handler
Jakub Pawlowski16a63402018-03-02 02:22:33 -080093 * @param socket_path Path to the socket
Hansong Zhangf88552c2018-02-01 18:02:53 -080094 * @return true on success, otherwise false
95 */
Jakub Pawlowski16a63402018-03-02 02:22:33 -080096bool UIPC_Open(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK* p_cback,
97 const char* socket_path);
The Android Open Source Project5738f832012-12-12 16:00:35 -080098
Hansong Zhangf88552c2018-02-01 18:02:53 -080099/**
100 * Closes a channel in UIPC or the entire UIPC module
Myles Watsonee96a3c2016-11-23 14:49:54 -0800101 *
Hansong Zhangf88552c2018-02-01 18:02:53 -0800102 * @param ch_id Channel ID; if ch_id is UIPC_CH_ID_ALL, then cleanup UIPC
Hansong Zhangf88552c2018-02-01 18:02:53 -0800103 */
Jakub Pawlowski4653f212018-03-01 16:23:58 -0800104void UIPC_Close(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800105
Hansong Zhangf88552c2018-02-01 18:02:53 -0800106/**
107 * Send a message over UIPC
Myles Watsonee96a3c2016-11-23 14:49:54 -0800108 *
Hansong Zhangf88552c2018-02-01 18:02:53 -0800109 * @param ch_id Channel ID
110 * @param msg_evt Message event type
111 * @param p_buf Buffer for the message
112 * @param msglen Message length
113 * @return true on success, otherwise false
114 */
Jakub Pawlowski4653f212018-03-01 16:23:58 -0800115bool UIPC_Send(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint16_t msg_evt,
116 const uint8_t* p_buf, uint16_t msglen);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800117
Hansong Zhangf88552c2018-02-01 18:02:53 -0800118/**
119 * Read a message from UIPC
Myles Watsonee96a3c2016-11-23 14:49:54 -0800120 *
Hansong Zhangf88552c2018-02-01 18:02:53 -0800121 * @param ch_id Channel ID
122 * @param p_msg_evt Message event type
123 * @param p_buf Buffer for the message
124 * @param len Bytes to read
125 * @return true on success, otherwise false
126 */
Jakub Pawlowski4653f212018-03-01 16:23:58 -0800127uint32_t UIPC_Read(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint16_t* p_msg_evt,
128 uint8_t* p_buf, uint32_t len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800129
Hansong Zhangf88552c2018-02-01 18:02:53 -0800130/**
131 * Control the UIPC parameter
Myles Watsonee96a3c2016-11-23 14:49:54 -0800132 *
Hansong Zhangf88552c2018-02-01 18:02:53 -0800133 * @param ch_id Channel ID
134 * @param request Request type
135 * @param param Optional parameters
136 * @return true on success, otherwise false
137 */
Jakub Pawlowski4653f212018-03-01 16:23:58 -0800138bool UIPC_Ioctl(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint32_t request,
139 void* param);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800140
Myles Watson911d1ae2016-11-28 16:44:40 -0800141#endif /* UIPC_H */