2009-09-04 19:01:32 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2011-10-10 20:39:48 +00:00
|
|
|
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
|
2018-10-22 18:56:07 +00:00
|
|
|
* Copyright (C) 2018 Gemalto M2M
|
2009-09-04 19:01:32 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-05-31 16:05:17 +00:00
|
|
|
#include <gatchat.h>
|
|
|
|
|
|
|
|
struct ofono_modem;
|
|
|
|
|
2010-06-11 01:06:26 +00:00
|
|
|
enum at_util_sms_store {
|
|
|
|
AT_UTIL_SMS_STORE_SM = 0,
|
|
|
|
AT_UTIL_SMS_STORE_ME = 1,
|
|
|
|
AT_UTIL_SMS_STORE_MT = 2,
|
|
|
|
AT_UTIL_SMS_STORE_SR = 3,
|
|
|
|
AT_UTIL_SMS_STORE_BM = 4,
|
|
|
|
};
|
|
|
|
|
2010-09-09 18:56:03 +00:00
|
|
|
/* 3GPP TS 27.007 Release 8 Section 5.5 */
|
|
|
|
enum at_util_charset {
|
|
|
|
AT_UTIL_CHARSET_GSM = 0x1,
|
|
|
|
AT_UTIL_CHARSET_HEX = 0x2,
|
|
|
|
AT_UTIL_CHARSET_IRA = 0x4,
|
|
|
|
AT_UTIL_CHARSET_PCCP437 = 0x8,
|
|
|
|
AT_UTIL_CHARSET_PCDN = 0x10,
|
|
|
|
AT_UTIL_CHARSET_UCS2 = 0x20,
|
|
|
|
AT_UTIL_CHARSET_UTF8 = 0x40,
|
|
|
|
AT_UTIL_CHARSET_8859_1 = 0x80,
|
|
|
|
AT_UTIL_CHARSET_8859_2 = 0x100,
|
|
|
|
AT_UTIL_CHARSET_8859_3 = 0x200,
|
|
|
|
AT_UTIL_CHARSET_8859_4 = 0x400,
|
|
|
|
AT_UTIL_CHARSET_8859_5 = 0x800,
|
|
|
|
AT_UTIL_CHARSET_8859_6 = 0x1000,
|
|
|
|
AT_UTIL_CHARSET_8859_C = 0x2000,
|
|
|
|
AT_UTIL_CHARSET_8859_A = 0x4000,
|
|
|
|
AT_UTIL_CHARSET_8859_G = 0x8000,
|
|
|
|
AT_UTIL_CHARSET_8859_H = 0x10000,
|
|
|
|
};
|
|
|
|
|
2011-07-22 13:18:02 +00:00
|
|
|
typedef void (*at_util_sim_inserted_cb_t)(gboolean present, void *userdata);
|
|
|
|
|
2009-09-04 19:01:32 +00:00
|
|
|
void decode_at_error(struct ofono_error *error, const char *final);
|
2009-10-28 17:22:06 +00:00
|
|
|
gint at_util_call_compare_by_status(gconstpointer a, gconstpointer b);
|
2009-11-07 07:21:25 +00:00
|
|
|
gint at_util_call_compare_by_phone_number(gconstpointer a, gconstpointer b);
|
2010-01-25 19:25:28 +00:00
|
|
|
gint at_util_call_compare_by_id(gconstpointer a, gconstpointer b);
|
2009-10-28 17:22:06 +00:00
|
|
|
gint at_util_call_compare(gconstpointer a, gconstpointer b);
|
2013-09-10 15:57:42 +00:00
|
|
|
GSList *at_util_parse_clcc(GAtResult *result, unsigned int *mpty_ids);
|
2009-12-09 18:49:43 +00:00
|
|
|
gboolean at_util_parse_reg(GAtResult *result, const char *prefix,
|
|
|
|
int *mode, int *status,
|
2010-01-18 14:30:13 +00:00
|
|
|
int *lac, int *ci, int *tech,
|
|
|
|
unsigned int vendor);
|
2009-12-09 18:49:43 +00:00
|
|
|
gboolean at_util_parse_reg_unsolicited(GAtResult *result, const char *prefix,
|
|
|
|
int *status, int *lac,
|
2010-01-18 14:30:13 +00:00
|
|
|
int *ci, int *tech,
|
|
|
|
unsigned int vendor);
|
2009-09-04 19:01:32 +00:00
|
|
|
|
2010-06-11 01:06:26 +00:00
|
|
|
gboolean at_util_parse_sms_index_delivery(GAtResult *result, const char *prefix,
|
|
|
|
enum at_util_sms_store *store,
|
|
|
|
int *index);
|
|
|
|
|
2010-09-09 18:56:03 +00:00
|
|
|
gboolean at_util_parse_cscs_supported(GAtResult *result, int *supported);
|
|
|
|
gboolean at_util_parse_cscs_query(GAtResult *result,
|
|
|
|
enum at_util_charset *charset);
|
|
|
|
|
2011-01-13 05:53:38 +00:00
|
|
|
gboolean at_util_parse_attr(GAtResult *result, const char *prefix,
|
|
|
|
const char **out_attr);
|
|
|
|
|
2011-07-22 13:18:02 +00:00
|
|
|
struct at_util_sim_state_query *at_util_sim_state_query_new(GAtChat *chat,
|
|
|
|
guint interval, guint num_times,
|
|
|
|
at_util_sim_inserted_cb_t cb,
|
2012-04-18 12:16:08 +00:00
|
|
|
void *userdata,
|
|
|
|
GDestroyNotify destroy);
|
2011-07-22 13:18:02 +00:00
|
|
|
void at_util_sim_state_query_free(struct at_util_sim_state_query *req);
|
|
|
|
|
2017-09-13 02:28:41 +00:00
|
|
|
int at_util_get_ipv4_address_and_netmask(const char *addrnetmask,
|
|
|
|
char *address, char *netmask);
|
2019-04-24 05:54:50 +00:00
|
|
|
int at_util_get_ipv6_address_and_netmask(const char *addrnetmask,
|
|
|
|
char *address, char *netmask);
|
|
|
|
|
2017-09-13 02:28:41 +00:00
|
|
|
|
2018-10-22 18:56:07 +00:00
|
|
|
int at_util_gprs_auth_method_to_auth_prot(
|
|
|
|
enum ofono_gprs_auth_method auth_method);
|
|
|
|
|
2018-10-22 18:56:08 +00:00
|
|
|
const char *at_util_gprs_proto_to_pdp_type(enum ofono_gprs_proto proto);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* at_util_get_cgdcont_command
|
|
|
|
* if the apn pointer is NULL, the context will be removed: the resulting
|
|
|
|
* string will be like: AT+CGDCONT=7
|
|
|
|
* but if apn pointer is not NULL and the string is empty, then
|
|
|
|
* this function will create a normal context with empty apn, like:
|
|
|
|
* AT+CGDCONT=4,"IPV6",""
|
|
|
|
*/
|
|
|
|
char *at_util_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto,
|
|
|
|
const char *apn);
|
|
|
|
|
2009-09-04 19:01:32 +00:00
|
|
|
struct cb_data {
|
atmodem: Add reference counting to cb_data
the cb_data can be used by creating the structure with cb_data_new,
and then there are two possibilities:
- use it in a single callback function, and destroy it with a call to
g_free.
Example:
- calling function:
struct cb_data *cbd = cb_data_new(cb, data);
if (g_at_chat_send(chat, buf, NULL, at_cgatt_cb, cbd, g_free) > 0)
return;
g_free(cbd);
- called function (here at_cgatt_cb):
static void at_cgatt_cb(gboolean ok, GAtResult *result,
gpointer user_data)
{
struct cb_data *cbd = user_data;
ofono_gprs_cb_t cb = cbd->cb;
struct ofono_error error;
decode_at_error(&error,
g_at_result_final_response(result));
cb(&error, cbd->data);
}
note the absence of explicit g_free(cbd);
- pass it through a train of callback functions, adding a reference at
each pass cb_data_ref, and removing it with cb_data_unref.
the use of cb_data_ref would replace a new object creation, while the
use of cb_data_unref the use of g_free.
Example:
- calling function:
struct cb_data *cbd = cb_data_new(cb, data);
// no cb_ref at the creation
if (g_at_chat_send(chat, buf, NULL,
at_lte_set_default_attach_info_cb,
cbd, cb_data_unref) > 0)
goto end;
cb_data_unref(cbd);
- called function 1 (at_lte_set_default_attach_info_cb):
static void at_lte_set_default_attach_info_cb(gboolean ok,
GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
cbd = cb_data_ref(cbd);
if (g_at_chat_send(chat, buf, NULL,
at_cgatt_cb, cbd, cb_data_unref) > 0)
return;
cb_data_unref(cbd);
}
- called function 2 (at_cgatt_cb):
like above. no call to g_free or cb_data_unref. The terminal function
doesn't need to know about the reference scheme.
2018-10-25 05:46:27 +00:00
|
|
|
gint ref_count;
|
2009-09-04 19:01:32 +00:00
|
|
|
void *cb;
|
|
|
|
void *data;
|
|
|
|
void *user;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct cb_data *cb_data_new(void *cb, void *data)
|
|
|
|
{
|
|
|
|
struct cb_data *ret;
|
|
|
|
|
2011-01-29 13:34:34 +00:00
|
|
|
ret = g_new0(struct cb_data, 1);
|
atmodem: Add reference counting to cb_data
the cb_data can be used by creating the structure with cb_data_new,
and then there are two possibilities:
- use it in a single callback function, and destroy it with a call to
g_free.
Example:
- calling function:
struct cb_data *cbd = cb_data_new(cb, data);
if (g_at_chat_send(chat, buf, NULL, at_cgatt_cb, cbd, g_free) > 0)
return;
g_free(cbd);
- called function (here at_cgatt_cb):
static void at_cgatt_cb(gboolean ok, GAtResult *result,
gpointer user_data)
{
struct cb_data *cbd = user_data;
ofono_gprs_cb_t cb = cbd->cb;
struct ofono_error error;
decode_at_error(&error,
g_at_result_final_response(result));
cb(&error, cbd->data);
}
note the absence of explicit g_free(cbd);
- pass it through a train of callback functions, adding a reference at
each pass cb_data_ref, and removing it with cb_data_unref.
the use of cb_data_ref would replace a new object creation, while the
use of cb_data_unref the use of g_free.
Example:
- calling function:
struct cb_data *cbd = cb_data_new(cb, data);
// no cb_ref at the creation
if (g_at_chat_send(chat, buf, NULL,
at_lte_set_default_attach_info_cb,
cbd, cb_data_unref) > 0)
goto end;
cb_data_unref(cbd);
- called function 1 (at_lte_set_default_attach_info_cb):
static void at_lte_set_default_attach_info_cb(gboolean ok,
GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
cbd = cb_data_ref(cbd);
if (g_at_chat_send(chat, buf, NULL,
at_cgatt_cb, cbd, cb_data_unref) > 0)
return;
cb_data_unref(cbd);
}
- called function 2 (at_cgatt_cb):
like above. no call to g_free or cb_data_unref. The terminal function
doesn't need to know about the reference scheme.
2018-10-25 05:46:27 +00:00
|
|
|
ret->ref_count = 1;
|
2009-09-04 19:01:32 +00:00
|
|
|
ret->cb = cb;
|
|
|
|
ret->data = data;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
atmodem: Add reference counting to cb_data
the cb_data can be used by creating the structure with cb_data_new,
and then there are two possibilities:
- use it in a single callback function, and destroy it with a call to
g_free.
Example:
- calling function:
struct cb_data *cbd = cb_data_new(cb, data);
if (g_at_chat_send(chat, buf, NULL, at_cgatt_cb, cbd, g_free) > 0)
return;
g_free(cbd);
- called function (here at_cgatt_cb):
static void at_cgatt_cb(gboolean ok, GAtResult *result,
gpointer user_data)
{
struct cb_data *cbd = user_data;
ofono_gprs_cb_t cb = cbd->cb;
struct ofono_error error;
decode_at_error(&error,
g_at_result_final_response(result));
cb(&error, cbd->data);
}
note the absence of explicit g_free(cbd);
- pass it through a train of callback functions, adding a reference at
each pass cb_data_ref, and removing it with cb_data_unref.
the use of cb_data_ref would replace a new object creation, while the
use of cb_data_unref the use of g_free.
Example:
- calling function:
struct cb_data *cbd = cb_data_new(cb, data);
// no cb_ref at the creation
if (g_at_chat_send(chat, buf, NULL,
at_lte_set_default_attach_info_cb,
cbd, cb_data_unref) > 0)
goto end;
cb_data_unref(cbd);
- called function 1 (at_lte_set_default_attach_info_cb):
static void at_lte_set_default_attach_info_cb(gboolean ok,
GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
cbd = cb_data_ref(cbd);
if (g_at_chat_send(chat, buf, NULL,
at_cgatt_cb, cbd, cb_data_unref) > 0)
return;
cb_data_unref(cbd);
}
- called function 2 (at_cgatt_cb):
like above. no call to g_free or cb_data_unref. The terminal function
doesn't need to know about the reference scheme.
2018-10-25 05:46:27 +00:00
|
|
|
static inline struct cb_data *cb_data_ref(struct cb_data *cbd)
|
|
|
|
{
|
|
|
|
cbd->ref_count++;
|
|
|
|
return cbd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void cb_data_unref(gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
|
|
|
if (--cbd->ref_count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:53:21 +00:00
|
|
|
static inline int at_util_convert_signal_strength(int strength)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (strength == 99)
|
|
|
|
result = -1;
|
|
|
|
else
|
|
|
|
result = (strength * 100) / 31;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-09-11 17:36:35 +00:00
|
|
|
#define CALLBACK_WITH_FAILURE(cb, args...) \
|
|
|
|
do { \
|
|
|
|
struct ofono_error cb_e; \
|
|
|
|
cb_e.type = OFONO_ERROR_TYPE_FAILURE; \
|
|
|
|
cb_e.error = 0; \
|
|
|
|
\
|
|
|
|
cb(&cb_e, ##args); \
|
|
|
|
} while (0) \
|
|
|
|
|
2009-11-18 23:43:45 +00:00
|
|
|
#define CALLBACK_WITH_SUCCESS(f, args...) \
|
|
|
|
do { \
|
|
|
|
struct ofono_error e; \
|
|
|
|
e.type = OFONO_ERROR_TYPE_NO_ERROR; \
|
|
|
|
e.error = 0; \
|
|
|
|
f(&e, ##args); \
|
2011-12-29 22:58:01 +00:00
|
|
|
} while (0)
|
2019-05-31 16:05:17 +00:00
|
|
|
|
|
|
|
GAtChat *at_util_open_device(struct ofono_modem *modem, const char *key,
|
|
|
|
GAtDebugFunc debug_func, char *debug_prefix,
|
|
|
|
char *tty_option, ...);
|