AT: Better failure handling and removed wrong unlock
[hayes-ril.git] / hayes-ril.h
1 /*
2  * This file is part of hayes-ril.
3  *
4  * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <at.h>
20
21 #ifndef _HAYES_RIL_H_
22 #define _HAYES_RIL_H_
23
24 /*
25  * Defines
26  */
27
28 #define RIL_DEVICE_LOCK(ril_device_p) pthread_mutex_lock(&(ril_device_p->handlers->transport->mutex));
29 #define RIL_DEVICE_UNLOCK(ril_device_p) pthread_mutex_unlock(&(ril_device_p->handlers->transport->mutex));
30 #define RIL_LOG_LOCK() pthread_mutex_lock(&(ril_globals.log_mutex));
31 #define RIL_LOG_UNLOCK() pthread_mutex_unlock(&(ril_globals.log_mutex));
32
33 #define DEV_GSM         RIL_DEVICE_TYPE_GSM
34 #define DEV_CDMA        RIL_DEVICE_TYPE_CDMA
35
36 /*
37  * Variables structures
38  */
39
40 // Device
41 enum ril_device_type {
42         RIL_DEVICE_TYPE_GSM,
43         RIL_DEVICE_TYPE_CDMA
44 };
45
46 struct ril_device_power_handlers {
47         void *sdata;
48         int (*sdata_create)(void **sdata);
49         int (*sdata_destroy)(void *sdata);
50
51         int (*power_on)(void *sdata);
52         int (*power_off)(void *sdata);
53
54         int (*suspend)(void *sdata);
55         int (*resume)(void *sdata);
56
57         int (*boot)(void *sdata);
58 };
59
60 struct ril_device_transport_handlers {
61         void *sdata;
62         int (*sdata_create)(void **sdata);
63         int (*sdata_destroy)(void *sdata);
64
65         int (*open)(void *sdata);
66         int (*close)(void *sdata);
67
68         int (*send)(void *sdata, void **data, int length);
69         int (*recv)(void *sdata, void **data, int length);
70
71         int (*recv_poll)(void *sdata);
72
73         pthread_t recv_thread;
74         pthread_mutex_t mutex;
75 };
76
77 struct ril_device_at_handlers {
78         void *sdata;
79         int (*sdata_create)(void **sdata);
80         int (*sdata_destroy)(void *sdata);
81
82         int (*power_on)(void *sdata);
83         int (*power_off)(void *sdata);
84         int (*setup)(void *sdata);
85 };
86
87 struct ril_device_handlers {
88         struct ril_device_power_handlers *power;
89         struct ril_device_transport_handlers *transport;
90         struct ril_device_at_handlers *at;
91 };
92
93 struct ril_device {
94         char *name;
95         char *tag;
96         void *sdata;
97
98         enum ril_device_type type;
99         struct ril_device_handlers *handlers;
100 };
101
102 extern struct ril_device *ril_device;
103 extern struct ril_globals ril_globals;
104
105 // RIL
106 struct ril_dispatch_unsol {
107         char *command;
108         void (*func)(struct at_response *response);
109 };
110
111 struct ril_globals {
112         // Dispatch
113         pthread_t dispatch_thread;
114         struct ril_dispatch_unsol *dispatch_unsol;
115         int dispatch_unsol_count;
116
117         // Log
118         pthread_mutex_t log_mutex;
119
120         // Power
121         RIL_RadioState radio_state;
122
123         // Network
124         char **registration_state;
125 };
126
127 /*
128  * Functions
129  */
130
131 // Device
132 void ril_device_register(struct ril_device **ril_device_p);
133 int ril_device_init(struct ril_device *ril_device_p);
134 int ril_device_setup(struct ril_device *ril_device_p);
135 int ril_device_deinit(struct ril_device *ril_device_p);
136 int ril_device_data_create(struct ril_device *ril_device_p);
137 int ril_device_data_destroy(struct ril_device *ril_device_p);
138
139 int ril_device_power_on(struct ril_device *ril_device_p);
140 int ril_device_power_off(struct ril_device *ril_device_p);
141 int ril_device_power_boot(struct ril_device *ril_device_p);
142
143 int ril_device_transport_open(struct ril_device *ril_device_p);
144 int ril_device_transport_close(struct ril_device *ril_device_p);
145 int ril_device_transport_send(struct ril_device *ril_device_p, void *data, int length);
146 int ril_device_transport_recv(struct ril_device *ril_device_p, void **data, int length);
147 int ril_device_transport_recv_poll(struct ril_device *ril_device_p);
148 int ril_device_transport_recv_thread_start(struct ril_device *ril_device_p);
149
150 int ril_device_at_power_on(struct ril_device *ril_device_p);
151 int ril_device_at_power_off(struct ril_device *ril_device_p);
152 int ril_device_at_setup(struct ril_device *ril_device_p);
153
154 // Utils
155 char *ril_status_string(int status);
156 void ril_recv_log(struct at_response *response);
157 void ril_send_log(struct at_request *request);
158 void ril_data_log(char *data, int length);
159
160 // Call
161 void ril_request_get_current_calls(RIL_Token t, void *data, size_t length);
162 void ril_call_state_changed(void *data);
163 void at_cring(struct at_response *response);
164 void ril_request_anwswer(RIL_Token t, void *data, size_t length);
165 void ril_request_dial(RIL_Token t, void *data, size_t length);
166 void no_carrier_unexpect(struct at_response *response);
167 void ril_request_hangup(RIL_Token t, void *data, size_t length);
168 void ril_request_hangup_waiting_or_background(RIL_Token t, void *data, size_t length);
169 void ril_request_hangup_foreground_resume_background(RIL_Token t, void *data, size_t length);
170 void ril_request_switch_waiting_or_holding_and_active(RIL_Token t, void *data, size_t length);
171
172 // Power
173 void ril_request_radio_power(RIL_Token t, void *data, size_t length);
174
175 // SIM
176 int at_cpin_expect(struct at_response *response, void *data, RIL_Token t);
177 void ril_request_get_sim_status(RIL_Token t, void *data, size_t length);
178 void ril_request_enter_sim_pin(RIL_Token t, void *data, size_t length);
179 void ril_request_sim_io(RIL_Token t, void *data, size_t length);
180
181 // Network
182 void ril_request_signal_strength(RIL_Token t, void *data, size_t length);
183 void at_creg_unexpect(struct at_response *response);
184 void ril_request_registration_state(RIL_Token t, void *data, size_t length);
185 void ril_request_operator(RIL_Token t, void *data, size_t length);
186
187 #endif