2 * This file is part of hayes-ril.
4 * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <telephony/ril.h>
21 #ifndef _HAYES_RIL_AT_H_
22 #define _HAYES_RIL_AT_H_
28 #define AT_SYNC_LOCK() pthread_mutex_lock(&(at_responses_handling.sync_mutex));
29 #define AT_SYNC_UNLOCK() pthread_mutex_unlock(&(at_responses_handling.sync_mutex));
30 #define AT_ASYNC_LOCK() pthread_mutex_lock(&(at_responses_handling.async_mutex));
31 #define AT_ASYNC_UNLOCK() pthread_mutex_unlock(&(at_responses_handling.async_mutex));
32 #define AT_RESPONSES_LOCK() pthread_mutex_lock(&(at_responses_handling.responses_mutex));
33 #define AT_RESPONSES_UNLOCK() pthread_mutex_unlock(&(at_responses_handling.responses_mutex));
34 #define AT_RESPONSES_QUEUE_LOCK() pthread_mutex_lock(&(at_responses_handling.responses_queue_mutex));
35 #define AT_RESPONSES_QUEUE_UNLOCK() pthread_mutex_unlock(&(at_responses_handling.responses_queue_mutex));
37 #define AT_PARSE_SINGLE_QUOTE (1 << 0)
38 #define AT_PARSE_DOUBLE_QUOTE (1 << 1)
41 * Variables structures
68 AT_STATUS_INTERNAL_ERROR,
72 AT_RESPONSE_UNHANDELD,
73 AT_RESPONSE_HANDLED_OK,
74 AT_RESPONSE_HANDLED_ERROR,
77 struct at_responses_queue {
78 struct at_response **responses;
82 typedef int (*at_async_request_cb)(struct at_response *response, void *data, RIL_Token t);
84 struct at_async_request {
89 at_async_request_cb func;
92 struct at_async_queue {
93 struct at_async_request **requests;
97 struct at_responses_handling {
98 pthread_mutex_t responses_queue_mutex;
99 struct at_responses_queue responses_queue;
100 pthread_mutex_t responses_mutex;
102 struct at_async_queue async_queue;
103 pthread_mutex_t async_mutex;
105 struct at_request *sync_request;
106 struct at_response *sync_response;
107 pthread_mutex_t sync_mutex;
115 int at_strings_compare(char *major, char *minor);
116 int at_commands_compare(char *major, char *minor);
117 void at_string_clean(char *string, int length);
118 int at_status_error(int status);
120 // Responses structures processing
121 int at_responses_process(struct at_response ***responses_p, char *data, int length);
122 void at_response_free(struct at_response *response);
123 void at_responses_free(struct at_response **responses, int responses_count);
125 // Responses handling
126 void at_responses_handling_init(void);
129 int at_response_queue(struct at_response *response);
130 struct at_response *at_response_dequeue(void);
133 int at_request_expect_to_func(char *command, void *data, RIL_Token t, at_async_request_cb func);
134 int at_response_expect_to_func(struct at_response *response);
137 int at_request_expect_status(struct at_request *request);
138 int at_response_expect_status(struct at_response *response);
139 int at_expect_status(struct at_request *request);
142 int at_request_send(struct at_request *request);
143 struct at_request *at_request_create(char *command, char *data);
144 void at_request_free(struct at_request *request);
147 int at_send(char *command, char *data);
148 int at_send_command(char *command);
149 int at_send_expect_status(char *command, char *data);
150 int at_send_expect_to_func(char *command, char *data, void *pdata, RIL_Token t, at_async_request_cb func);