1 /* $Id$ */
2 /* Copyright (c) 2011-2016 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Desktop Phone */
4 /* This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>. */
15 
16 
17 
18 #ifndef DESKTOP_PHONE_MODEM_H
19 # define DESKTOP_PHONE_MODEM_H
20 
21 # include <sys/types.h>
22 
23 
24 /* Modem */
25 /* types */
26 typedef struct _Modem Modem;
27 
28 typedef enum _ModemAuthenticationMethod
29 {
30 	MODEM_AUTHENTICATION_METHOD_NONE = 0,
31 	MODEM_AUTHENTICATION_METHOD_PASSWORD,
32 	MODEM_AUTHENTICATION_METHOD_PIN
33 } ModemAuthenticationMethod;
34 
35 typedef enum _ModemAuthenticationStatus
36 {
37 	MODEM_AUTHENTICATION_STATUS_UNKNOWN = 0,
38 	MODEM_AUTHENTICATION_STATUS_OK,
39 	MODEM_AUTHENTICATION_STATUS_REQUIRED,
40 	MODEM_AUTHENTICATION_STATUS_ERROR
41 } ModemAuthenticationStatus;
42 
43 typedef enum _ModemBatteryStatus
44 {
45 	MODEM_BATTERY_STATUS_UNKNOWN = 0,
46 	MODEM_BATTERY_STATUS_NONE,
47 	MODEM_BATTERY_STATUS_CONNECTED,
48 	MODEM_BATTERY_STATUS_CHARGING,
49 	MODEM_BATTERY_STATUS_ERROR
50 } ModemBatteryStatus;
51 
52 typedef enum _ModemCallDirection
53 {
54 	MODEM_CALL_DIRECTION_NONE = 0,
55 	MODEM_CALL_DIRECTION_INCOMING,
56 	MODEM_CALL_DIRECTION_OUTGOING
57 } ModemCallDirection;
58 
59 typedef enum _ModemCallStatus
60 {
61 	MODEM_CALL_STATUS_NONE = 0,
62 	MODEM_CALL_STATUS_RINGING,
63 	MODEM_CALL_STATUS_ACTIVE,
64 	MODEM_CALL_STATUS_BUSY
65 } ModemCallStatus;
66 
67 typedef enum _ModemCallType
68 {
69 	MODEM_CALL_TYPE_VOICE = 0,
70 	MODEM_CALL_TYPE_DATA
71 } ModemCallType;
72 
73 typedef enum _ModemContactStatus
74 {
75 	MODEM_CONTACT_STATUS_OFFLINE = 0,
76 	MODEM_CONTACT_STATUS_AWAY,
77 	MODEM_CONTACT_STATUS_BUSY,
78 	MODEM_CONTACT_STATUS_IDLE,
79 	MODEM_CONTACT_STATUS_ONLINE
80 } ModemContactStatus;
81 # define MODEM_CONTACT_STATUS_LAST	MODEM_CONTACT_STATUS_ONLINE
82 # define MODEM_CONTACT_STATUS_COUNT	(MODEM_CONTACT_STATUS_LAST + 1)
83 
84 typedef enum _ModemMessageEncoding
85 {
86 	MODEM_MESSAGE_ENCODING_NONE = 0,
87 	MODEM_MESSAGE_ENCODING_DATA,
88 	MODEM_MESSAGE_ENCODING_ASCII,
89 	MODEM_MESSAGE_ENCODING_UTF8
90 } ModemMessageEncoding;
91 
92 typedef enum _ModemMessageFolder
93 {
94 	MODEM_MESSAGE_FOLDER_UNKNOWN = 0,
95 	MODEM_MESSAGE_FOLDER_INBOX,
96 	MODEM_MESSAGE_FOLDER_OUTBOX,
97 	MODEM_MESSAGE_FOLDER_DRAFTS,
98 	MODEM_MESSAGE_FOLDER_TRASH,
99 	MODEM_MESSAGE_FOLDER_OTHER
100 } ModemMessageFolder;
101 
102 typedef enum _ModemMessageStatus
103 {
104 	MODEM_MESSAGE_STATUS_NEW = 0,
105 	MODEM_MESSAGE_STATUS_UNREAD,
106 	MODEM_MESSAGE_STATUS_READ
107 } ModemMessageStatus;
108 
109 typedef enum _ModemNotificationType
110 {
111 	MODEM_NOTIFICATION_TYPE_INFO = 0,
112 	MODEM_NOTIFICATION_TYPE_ERROR,
113 	MODEM_NOTIFICATION_TYPE_WARNING
114 } ModemNotificationType;
115 
116 typedef enum _ModemRegistrationMode
117 {
118 	MODEM_REGISTRATION_MODE_UNKNOWN = 0,
119 	MODEM_REGISTRATION_MODE_AUTOMATIC,
120 	MODEM_REGISTRATION_MODE_MANUAL,
121 	MODEM_REGISTRATION_MODE_DISABLED
122 } ModemRegistrationMode;
123 
124 typedef enum _ModemRegistrationStatus
125 {
126 	MODEM_REGISTRATION_STATUS_UNKNOWN = 0,
127 	MODEM_REGISTRATION_STATUS_NOT_SEARCHING,
128 	MODEM_REGISTRATION_STATUS_SEARCHING,
129 	MODEM_REGISTRATION_STATUS_REGISTERED,
130 	MODEM_REGISTRATION_STATUS_DENIED
131 } ModemRegistrationStatus;
132 
133 typedef enum _ModemStatus
134 {
135 	MODEM_STATUS_UNKNOWN = 0,
136 	MODEM_STATUS_UNAVAILABLE,
137 	MODEM_STATUS_OFFLINE,
138 	MODEM_STATUS_ONLINE
139 } ModemStatus;
140 
141 /* ModemConfig */
142 typedef enum _ModemConfigType
143 {
144 	MCT_NONE = 0,
145 	/* values */
146 	MCT_BOOLEAN,
147 	MCT_FILENAME,
148 	MCT_PASSWORD,
149 	MCT_STRING,
150 	MCT_UINT32,
151 	/* layout */
152 	MCT_SECTION,
153 	MCT_SUBSECTION,
154 	MCT_SEPARATOR
155 } ModemConfigType;
156 
157 typedef const struct _ModemConfig
158 {
159 	char const * name;
160 	char const * title;
161 	ModemConfigType type;
162 } ModemConfig;
163 
164 /* ModemEvent */
165 typedef enum _ModemEventType
166 {
167 	MODEM_EVENT_TYPE_ERROR = 0,
168 	MODEM_EVENT_TYPE_AUTHENTICATION,
169 	MODEM_EVENT_TYPE_BATTERY_LEVEL,
170 	MODEM_EVENT_TYPE_CALL,
171 	MODEM_EVENT_TYPE_CONNECTION,
172 	MODEM_EVENT_TYPE_CONTACT,
173 	MODEM_EVENT_TYPE_CONTACT_DELETED,
174 	MODEM_EVENT_TYPE_MESSAGE,
175 	MODEM_EVENT_TYPE_MESSAGE_DELETED,
176 	MODEM_EVENT_TYPE_MESSAGE_SENT,
177 	MODEM_EVENT_TYPE_MODEL,
178 	MODEM_EVENT_TYPE_NOTIFICATION,
179 	MODEM_EVENT_TYPE_REGISTRATION,
180 	MODEM_EVENT_TYPE_STATUS
181 } ModemEventType;
182 # define MODEM_EVENT_TYPE_LAST MODEM_EVENT_TYPE_STATUS
183 # define MODEM_EVENT_TYPE_COUNT (MODEM_EVENT_TYPE_LAST + 1)
184 
185 typedef union _ModemEvent
186 {
187 	ModemEventType type;
188 
189 	/* MODEM_EVENT_TYPE_ERROR */
190 	struct
191 	{
192 		ModemEventType type;
193 		char const * message;
194 	} error;
195 
196 	/* MODEM_EVENT_TYPE_AUTHENTICATION */
197 	struct
198 	{
199 		ModemEventType type;
200 		char const * name;
201 		ModemAuthenticationMethod method;
202 		ModemAuthenticationStatus status;
203 		int retries;
204 		char const * error;
205 	} authentication;
206 
207 	/* MODEM_EVENT_TYPE_BATTERY_LEVEL */
208 	struct
209 	{
210 		ModemEventType type;
211 		ModemBatteryStatus status;
212 		double level;
213 		int charging;
214 	} battery_level;
215 
216 	/* MODEM_EVENT_TYPE_CALL */
217 	struct
218 	{
219 		ModemEventType type;
220 		ModemCallType call_type;
221 		ModemCallDirection direction;
222 		ModemCallStatus status;
223 		char const * number;
224 	} call;
225 
226 	/* MODEM_EVENT_TYPE_CONNECTION */
227 	struct
228 	{
229 		ModemEventType type;
230 		int connected;
231 		size_t in;
232 		size_t out;
233 	} connection;
234 
235 	/* MODEM_EVENT_TYPE_CONTACT */
236 	struct
237 	{
238 		ModemEventType type;
239 		unsigned int id;
240 		ModemContactStatus status;
241 		char const * name;
242 		char const * number;
243 	} contact;
244 
245 	/* MODEM_EVENT_TYPE_CONTACT_DELETED */
246 	struct
247 	{
248 		ModemEventType type;
249 		unsigned int id;
250 	} contact_deleted;
251 
252 	/* MODEM_EVENT_TYPE_MESSAGE */
253 	struct
254 	{
255 		ModemEventType type;
256 		unsigned int id;
257 		time_t date;
258 		char const * number;
259 		ModemMessageFolder folder;
260 		ModemMessageStatus status;
261 		ModemMessageEncoding encoding;
262 		size_t length;
263 		char const * content;
264 	} message;
265 
266 	/* MODEM_EVENT_TYPE_MESSAGE_DELETED */
267 	struct
268 	{
269 		ModemEventType type;
270 		unsigned int id;
271 	} message_deleted;
272 
273 	/* MODEM_EVENT_TYPE_MESSAGE_SENT */
274 	struct
275 	{
276 		ModemEventType type;
277 		char const * error;
278 		unsigned int id;
279 	} message_sent;
280 
281 	/* MODEM_EVENT_TYPE_MODEL */
282 	struct
283 	{
284 		ModemEventType type;
285 		char const * vendor;
286 		char const * name;
287 		char const * version;
288 		char const * serial;
289 		char const * identity;
290 	} model;
291 
292 	/* MODEM_EVENT_TYPE_NOTIFICATION */
293 	struct
294 	{
295 		ModemEventType type;
296 		ModemNotificationType ntype;
297 		char const * title;
298 		char const * content;
299 	} notification;
300 
301 	/* MODEM_EVENT_TYPE_REGISTRATION */
302 	struct
303 	{
304 		ModemEventType type;
305 		ModemRegistrationMode mode;
306 		ModemRegistrationStatus status;
307 		char const * media;
308 		char const * _operator;
309 		double signal;
310 		int roaming;
311 	} registration;
312 
313 	/* MODEM_EVENT_TYPE_STATUS */
314 	struct {
315 		ModemEventType type;
316 		ModemStatus status;
317 	} status;
318 } ModemEvent;
319 
320 /* ModemRequest */
321 typedef enum _ModemRequestType
322 {
323 	MODEM_REQUEST_AUTHENTICATE = 0,
324 	MODEM_REQUEST_BATTERY_LEVEL,
325 	MODEM_REQUEST_CALL,
326 	MODEM_REQUEST_CALL_ANSWER,
327 	MODEM_REQUEST_CALL_HANGUP,
328 	MODEM_REQUEST_CALL_LAST,
329 	MODEM_REQUEST_CALL_PRESENTATION,
330 	MODEM_REQUEST_CALL_WAITING_CONTROL,
331 	MODEM_REQUEST_CONNECTIVITY,
332 	MODEM_REQUEST_CONTACT,
333 	MODEM_REQUEST_CONTACT_DELETE,
334 	MODEM_REQUEST_CONTACT_EDIT,
335 	MODEM_REQUEST_CONTACT_LIST,
336 	MODEM_REQUEST_CONTACT_NEW,
337 	MODEM_REQUEST_DTMF_SEND,
338 	MODEM_REQUEST_LINE_PRESENTATION,
339 	MODEM_REQUEST_MESSAGE,
340 	MODEM_REQUEST_MESSAGE_DELETE,
341 	MODEM_REQUEST_MESSAGE_LIST,
342 	MODEM_REQUEST_MESSAGE_SEND,
343 	MODEM_REQUEST_MUTE,
344 	MODEM_REQUEST_PASSWORD_SET,
345 	MODEM_REQUEST_REGISTRATION,
346 	MODEM_REQUEST_SIGNAL_LEVEL,
347 	MODEM_REQUEST_UNSUPPORTED
348 } ModemRequestType;
349 # define MODEM_REQUEST_LAST MODEM_REQUEST_UNSUPPORTED
350 # define MODEM_REQUEST_COUNT (MODEM_REQUEST_LAST + 1)
351 
352 typedef union _ModemRequest
353 {
354 	ModemRequestType type;
355 
356 	/* MODEM_REQUEST_AUTHENTICATE */
357 	struct
358 	{
359 		ModemRequestType type;
360 		char const * name;
361 		char const * username;
362 		char const * password;
363 	} authenticate;
364 
365 	/* MODEM_REQUEST_CALL */
366 	struct
367 	{
368 		ModemRequestType type;
369 		ModemCallType call_type;
370 		char const * number;
371 		int anonymous;
372 	} call;
373 
374 	/* MODEM_REQUEST_CALL_PRESENTATION */
375 	struct
376 	{
377 		ModemRequestType type;
378 		unsigned int enabled;
379 	} call_presentation;
380 
381 	/* MODEM_REQUEST_CONNECTIVITY */
382 	struct
383 	{
384 		ModemRequestType type;
385 		unsigned int enabled;
386 	} connectivity;
387 
388 	/* MODEM_REQUEST_CONTACT, MODEM_REQUEST_CONTACT_DELETE */
389 	struct
390 	{
391 		ModemRequestType type;
392 		unsigned int id;
393 	} contact, contact_delete;
394 
395 	/* MODEM_REQUEST_CONTACT_EDIT */
396 	struct
397 	{
398 		ModemRequestType type;
399 		unsigned int id;
400 		char const * name;
401 		char const * number;
402 	} contact_edit;
403 
404 	/* MODEM_REQUEST_CONTACT_NEW */
405 	struct
406 	{
407 		ModemRequestType type;
408 		char const * name;
409 		char const * number;
410 	} contact_new;
411 
412 	/* MODEM_REQUEST_DTMF_SEND */
413 	struct
414 	{
415 		ModemRequestType type;
416 		char dtmf;
417 	} dtmf_send;
418 
419 	/* MODEM_REQUEST_MESSAGE, MODEM_REQUEST_MESSAGE_DELETE */
420 	struct
421 	{
422 		ModemRequestType type;
423 		unsigned int id;
424 	} message, message_delete;
425 
426 	/* MODEM_REQUEST_MESSAGE_SEND */
427 	struct
428 	{
429 		ModemRequestType type;
430 		char const * number;
431 		ModemMessageEncoding encoding;
432 		size_t length;
433 		char const * content;
434 	} message_send;
435 
436 	/* MODEM_REQUEST_MUTE */
437 	struct
438 	{
439 		ModemRequestType type;
440 		unsigned int enabled;
441 	} mute;
442 
443 	/* MODEM_REQUEST_PASSWORD_SET */
444 	struct
445 	{
446 		ModemRequestType type;
447 		char const * name;
448 		char const * oldpassword;
449 		char const * newpassword;
450 	} password_set;
451 
452 	/* MODEM_REQUEST_PLUGIN */
453 	struct
454 	{
455 		ModemRequestType type;
456 		void * data;
457 	} plugin;
458 
459 	/* MODEM_REQUEST_REGISTRATION */
460 	struct
461 	{
462 		ModemRequestType type;
463 		ModemRegistrationMode mode;
464 		char const * _operator;
465 	} registration;
466 
467 	/* MODEM_REQUEST_UNSUPPORTED */
468 	struct
469 	{
470 		ModemRequestType type;
471 		char const * modem;
472 		unsigned int request_type;
473 		void * request;
474 		size_t size;
475 	} unsupported;
476 } ModemRequest;
477 
478 typedef struct _ModemPluginHelper
479 {
480 	Modem * modem;
481 	char const * (*config_get)(Modem * modem, char const * variable);
482 	int (*config_set)(Modem * modem, char const * variable,
483 			char const * value);
484 	int (*error)(Modem * modem, char const * message, int ret);
485 	void (*event)(Modem * modem, ModemEvent * event);
486 } ModemPluginHelper;
487 
488 typedef struct _ModemPlugin ModemPlugin;
489 
490 typedef const struct _ModemPluginDefinition ModemPluginDefinition;
491 
492 struct _ModemPluginDefinition
493 {
494 	char const * name;
495 	char const * icon;
496 	ModemConfig * config;
497 	ModemPlugin * (*init)(ModemPluginHelper * helper);
498 	void (*destroy)(ModemPlugin * plugin);
499 	int (*start)(ModemPlugin * plugin, unsigned int retry);
500 	int (*stop)(ModemPlugin * plugin);
501 	int (*request)(ModemPlugin * plugin, ModemRequest * request);
502 	int (*trigger)(ModemPlugin * plugin, ModemEventType event);
503 };
504 
505 #endif /* !DESKTOP_PHONE_MODEM_H */
506