The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2007-2012 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 | #ifndef UIPC_H |
| 19 | #define UIPC_H |
| 20 | |
Hansong Zhang | be754da | 2018-01-19 12:23:57 -0800 | [diff] [blame] | 21 | #include <mutex> |
| 22 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 23 | #define UIPC_CH_ID_AV_CTRL 0 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 24 | #define UIPC_CH_ID_AV_AUDIO 1 |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 25 | #define UIPC_CH_NUM 2 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 26 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 27 | #define UIPC_CH_ID_ALL 3 /* used to address all the ch id at once */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | |
| 29 | #define DEFAULT_READ_POLL_TMO_MS 100 |
| 30 | |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 31 | typedef uint8_t tUIPC_CH_ID; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 32 | |
| 33 | /* Events generated */ |
| 34 | typedef enum { |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 35 | 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 40 | } tUIPC_EVENT; |
| 41 | |
| 42 | /* |
| 43 | * UIPC IOCTL Requests |
| 44 | */ |
| 45 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 46 | #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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 50 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 51 | typedef 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 57 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 58 | const char* dump_uipc_event(tUIPC_EVENT event); |
| 59 | |
Jakub Pawlowski | 4653f21 | 2018-03-01 16:23:58 -0800 | [diff] [blame] | 60 | typedef 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 | |
| 68 | struct 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 Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 81 | /** |
| 82 | * Initialize UIPC module |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 83 | * |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 84 | * @param user User ID who uses UIPC |
| 85 | */ |
Jakub Pawlowski | 4653f21 | 2018-03-01 16:23:58 -0800 | [diff] [blame] | 86 | std::unique_ptr<tUIPC_STATE> UIPC_Init(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 87 | |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 88 | /** |
| 89 | * Open a UIPC channel |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 90 | * |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 91 | * @param ch_id Channel ID |
| 92 | * @param p_cback Callback handler |
Jakub Pawlowski | 16a6340 | 2018-03-02 02:22:33 -0800 | [diff] [blame] | 93 | * @param socket_path Path to the socket |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 94 | * @return true on success, otherwise false |
| 95 | */ |
Jakub Pawlowski | 16a6340 | 2018-03-02 02:22:33 -0800 | [diff] [blame] | 96 | bool UIPC_Open(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, tUIPC_RCV_CBACK* p_cback, |
| 97 | const char* socket_path); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 98 | |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 99 | /** |
| 100 | * Closes a channel in UIPC or the entire UIPC module |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 101 | * |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 102 | * @param ch_id Channel ID; if ch_id is UIPC_CH_ID_ALL, then cleanup UIPC |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 103 | */ |
Jakub Pawlowski | 4653f21 | 2018-03-01 16:23:58 -0800 | [diff] [blame] | 104 | void UIPC_Close(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 105 | |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 106 | /** |
| 107 | * Send a message over UIPC |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 108 | * |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 109 | * @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 Pawlowski | 4653f21 | 2018-03-01 16:23:58 -0800 | [diff] [blame] | 115 | bool 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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 117 | |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 118 | /** |
| 119 | * Read a message from UIPC |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 120 | * |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 121 | * @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 Pawlowski | 4653f21 | 2018-03-01 16:23:58 -0800 | [diff] [blame] | 127 | uint32_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 Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 129 | |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 130 | /** |
| 131 | * Control the UIPC parameter |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 132 | * |
Hansong Zhang | f88552c | 2018-02-01 18:02:53 -0800 | [diff] [blame] | 133 | * @param ch_id Channel ID |
| 134 | * @param request Request type |
| 135 | * @param param Optional parameters |
| 136 | * @return true on success, otherwise false |
| 137 | */ |
Jakub Pawlowski | 4653f21 | 2018-03-01 16:23:58 -0800 | [diff] [blame] | 138 | bool UIPC_Ioctl(tUIPC_STATE& uipc, tUIPC_CH_ID ch_id, uint32_t request, |
| 139 | void* param); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 140 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 141 | #endif /* UIPC_H */ |