mirror of git://git.sysmocom.de/ofono
Update netreg AT modem driver to the new API
This commit is contained in:
parent
5b1f5ba084
commit
7ad2eb2342
|
@ -25,7 +25,6 @@ struct at_data {
|
||||||
GIOChannel *io;
|
GIOChannel *io;
|
||||||
char *driver;
|
char *driver;
|
||||||
|
|
||||||
struct netreg_data *netreg;
|
|
||||||
struct voicecall_data *voicecall;
|
struct voicecall_data *voicecall;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,8 +62,8 @@ static inline struct cb_data *cb_data_new(struct ofono_modem *modem,
|
||||||
|
|
||||||
extern struct ofono_error g_ok;
|
extern struct ofono_error g_ok;
|
||||||
|
|
||||||
extern void at_network_registration_init(struct ofono_modem *modem);
|
extern void at_netreg_init();
|
||||||
extern void at_network_registration_exit(struct ofono_modem *modem);
|
extern void at_netreg_exit();
|
||||||
|
|
||||||
extern void at_call_forwarding_init();
|
extern void at_call_forwarding_init();
|
||||||
extern void at_call_forwarding_exit();
|
extern void at_call_forwarding_exit();
|
||||||
|
|
|
@ -109,7 +109,6 @@ static void at_destroy(struct at_data *at)
|
||||||
|
|
||||||
static void interface_exit(struct at_data *at)
|
static void interface_exit(struct at_data *at)
|
||||||
{
|
{
|
||||||
at_network_registration_exit(at->modem);
|
|
||||||
at_voicecall_exit(at->modem);
|
at_voicecall_exit(at->modem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +370,7 @@ static void create_cb(GIOChannel *io, gboolean success, gpointer user)
|
||||||
ofono_sim_create(at->modem, "generic_at", at->parser);
|
ofono_sim_create(at->modem, "generic_at", at->parser);
|
||||||
ofono_call_forwarding_create(at->modem, "generic_at", at->parser);
|
ofono_call_forwarding_create(at->modem, "generic_at", at->parser);
|
||||||
ofono_call_settings_create(at->modem, "generic_at", at->parser);
|
ofono_call_settings_create(at->modem, "generic_at", at->parser);
|
||||||
at_network_registration_init(at->modem);
|
ofono_netreg_create(at->modem, "generic_at", at->parser);
|
||||||
at_voicecall_init(at->modem);
|
at_voicecall_init(at->modem);
|
||||||
ofono_call_meter_create(at->modem, "generic_at", at->parser);
|
ofono_call_meter_create(at->modem, "generic_at", at->parser);
|
||||||
ofono_call_barring_create(at->modem, "generic_at", at->parser);
|
ofono_call_barring_create(at->modem, "generic_at", at->parser);
|
||||||
|
@ -547,6 +546,7 @@ static int atmodem_init(void)
|
||||||
at_ussd_init();
|
at_ussd_init();
|
||||||
at_sms_init();
|
at_sms_init();
|
||||||
at_sim_init();
|
at_sim_init();
|
||||||
|
at_netreg_init();
|
||||||
|
|
||||||
manager_init(conn);
|
manager_init(conn);
|
||||||
|
|
||||||
|
@ -568,6 +568,7 @@ static void atmodem_exit(void)
|
||||||
at_call_meter_exit();
|
at_call_meter_exit();
|
||||||
at_call_forwarding_exit();
|
at_call_forwarding_exit();
|
||||||
at_call_barring_exit();
|
at_call_barring_exit();
|
||||||
|
at_netreg_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
OFONO_PLUGIN_DEFINE(atmodem, "AT modem driver", VERSION,
|
OFONO_PLUGIN_DEFINE(atmodem, "AT modem driver", VERSION,
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include <ofono/log.h>
|
#include <ofono/log.h>
|
||||||
#include <ofono/modem.h>
|
#include <ofono/modem.h>
|
||||||
#include "driver.h"
|
#include <ofono/netreg.h>
|
||||||
|
|
||||||
#include "gatchat.h"
|
#include "gatchat.h"
|
||||||
#include "gatresult.h"
|
#include "gatresult.h"
|
||||||
|
@ -45,6 +45,7 @@ static const char *cops_prefix[] = { "+COPS:", NULL };
|
||||||
static const char *csq_prefix[] = { "+CSQ:", NULL };
|
static const char *csq_prefix[] = { "+CSQ:", NULL };
|
||||||
|
|
||||||
struct netreg_data {
|
struct netreg_data {
|
||||||
|
GAtChat *chat;
|
||||||
char mcc[OFONO_MAX_MCC_LENGTH + 1];
|
char mcc[OFONO_MAX_MCC_LENGTH + 1];
|
||||||
char mnc[OFONO_MAX_MNC_LENGTH + 1];
|
char mnc[OFONO_MAX_MNC_LENGTH + 1];
|
||||||
};
|
};
|
||||||
|
@ -64,7 +65,7 @@ static void at_creg_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
ofono_registration_status_cb_t cb = cbd->cb;
|
ofono_netreg_status_cb_t cb = cbd->cb;
|
||||||
int status;
|
int status;
|
||||||
const char *str;
|
const char *str;
|
||||||
int lac = -1, ci = -1, tech = -1;
|
int lac = -1, ci = -1, tech = -1;
|
||||||
|
@ -110,17 +111,17 @@ out:
|
||||||
cb(&error, status, lac, ci, tech, cbd->data);
|
cb(&error, status, lac, ci, tech, cbd->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_registration_status(struct ofono_modem *modem,
|
static void at_registration_status(struct ofono_netreg *netreg,
|
||||||
ofono_registration_status_cb_t cb,
|
ofono_netreg_status_cb_t cb,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
struct cb_data *cbd = cb_data_new(modem, cb, data);
|
struct cb_data *cbd = cb_data_new(NULL, cb, data);
|
||||||
|
|
||||||
if (!cbd)
|
if (!cbd)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_at_chat_send(at->parser, "AT+CREG?", creg_prefix,
|
if (g_at_chat_send(nd->chat, "AT+CREG?", creg_prefix,
|
||||||
at_creg_cb, cbd, g_free) > 0)
|
at_creg_cb, cbd, g_free) > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -137,8 +138,8 @@ error:
|
||||||
static void cops_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
static void cops_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
struct at_data *at = ofono_modem_get_userdata(cbd->modem);
|
struct netreg_data *nd = ofono_netreg_get_data(cbd->user);
|
||||||
ofono_current_operator_cb_t cb = cbd->cb;
|
ofono_netreg_operator_cb_t cb = cbd->cb;
|
||||||
struct ofono_network_operator op;
|
struct ofono_network_operator op;
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
int format, tech;
|
int format, tech;
|
||||||
|
@ -148,7 +149,7 @@ static void cops_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
dump_response("cops_cb", ok, result);
|
dump_response("cops_cb", ok, result);
|
||||||
decode_at_error(&error, g_at_result_final_response(result));
|
decode_at_error(&error, g_at_result_final_response(result));
|
||||||
|
|
||||||
if (!ok || at->netreg->mcc[0] == '\0' || at->netreg->mnc[0] == '\0') {
|
if (!ok || nd->mcc[0] == '\0' || nd->mnc[0] == '\0') {
|
||||||
cb(&error, NULL, cbd->data);
|
cb(&error, NULL, cbd->data);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -175,17 +176,16 @@ static void cops_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
strncpy(op.name, name, OFONO_MAX_OPERATOR_NAME_LENGTH);
|
strncpy(op.name, name, OFONO_MAX_OPERATOR_NAME_LENGTH);
|
||||||
op.name[OFONO_MAX_OPERATOR_NAME_LENGTH] = '\0';
|
op.name[OFONO_MAX_OPERATOR_NAME_LENGTH] = '\0';
|
||||||
|
|
||||||
strncpy(op.mcc, at->netreg->mcc, OFONO_MAX_MCC_LENGTH);
|
strncpy(op.mcc, nd->mcc, OFONO_MAX_MCC_LENGTH);
|
||||||
op.mcc[OFONO_MAX_MCC_LENGTH] = '\0';
|
op.mcc[OFONO_MAX_MCC_LENGTH] = '\0';
|
||||||
|
|
||||||
strncpy(op.mnc, at->netreg->mnc, OFONO_MAX_MNC_LENGTH);
|
strncpy(op.mnc, nd->mnc, OFONO_MAX_MNC_LENGTH);
|
||||||
op.mnc[OFONO_MAX_MNC_LENGTH] = '\0';
|
op.mnc[OFONO_MAX_MNC_LENGTH] = '\0';
|
||||||
|
|
||||||
op.status = -1;
|
op.status = -1;
|
||||||
op.tech = tech;
|
op.tech = tech;
|
||||||
|
|
||||||
ofono_debug("cops_cb: %s, %s %s %d", name, at->netreg->mcc,
|
ofono_debug("cops_cb: %s, %s %s %d", name, nd->mcc, nd->mnc, tech);
|
||||||
at->netreg->mnc, tech);
|
|
||||||
|
|
||||||
cb(&error, &op, cbd->data);
|
cb(&error, &op, cbd->data);
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ error:
|
||||||
static void cops_numeric_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
static void cops_numeric_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
struct at_data *at = ofono_modem_get_userdata(cbd->modem);
|
struct netreg_data *nd = ofono_netreg_get_data(cbd->user);
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
const char *str;
|
const char *str;
|
||||||
int format;
|
int format;
|
||||||
|
@ -233,41 +233,42 @@ static void cops_numeric_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
strlen(str) == 0)
|
strlen(str) == 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
extract_mcc_mnc(str, at->netreg->mcc, at->netreg->mnc);
|
extract_mcc_mnc(str, nd->mcc, nd->mnc);
|
||||||
|
|
||||||
ofono_debug("Cops numeric got mcc: %s, mnc: %s",
|
ofono_debug("Cops numeric got mcc: %s, mnc: %s", nd->mcc, nd->mnc);
|
||||||
at->netreg->mcc, at->netreg->mnc);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
at->netreg->mcc[0] = '\0';
|
nd->mcc[0] = '\0';
|
||||||
at->netreg->mnc[0] = '\0';
|
nd->mnc[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_current_operator(struct ofono_modem *modem,
|
static void at_current_operator(struct ofono_netreg *netreg,
|
||||||
ofono_current_operator_cb_t cb, void *data)
|
ofono_netreg_operator_cb_t cb, void *data)
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
struct cb_data *cbd = cb_data_new(modem, cb, data);
|
struct cb_data *cbd = cb_data_new(NULL, cb, data);
|
||||||
gboolean ok;
|
gboolean ok;
|
||||||
|
|
||||||
if (!cbd)
|
if (!cbd)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ok = g_at_chat_send(at->parser, "AT+COPS=3,2", none_prefix,
|
cbd->user = netreg;
|
||||||
|
|
||||||
|
ok = g_at_chat_send(nd->chat, "AT+COPS=3,2", none_prefix,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
ok = g_at_chat_send(at->parser, "AT+COPS?", cops_prefix,
|
ok = g_at_chat_send(nd->chat, "AT+COPS?", cops_prefix,
|
||||||
cops_numeric_cb, cbd, NULL);
|
cops_numeric_cb, cbd, NULL);
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
ok = g_at_chat_send(at->parser, "AT+COPS=3,0", none_prefix,
|
ok = g_at_chat_send(nd->chat, "AT+COPS=3,0", none_prefix,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
ok = g_at_chat_send(at->parser, "AT+COPS?", cops_prefix,
|
ok = g_at_chat_send(nd->chat, "AT+COPS?", cops_prefix,
|
||||||
cops_cb, cbd, NULL);
|
cops_cb, cbd, NULL);
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
|
@ -286,7 +287,7 @@ error:
|
||||||
static void cops_list_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
static void cops_list_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
ofono_operator_list_cb_t cb = cbd->cb;
|
ofono_netreg_operator_list_cb_t cb = cbd->cb;
|
||||||
struct ofono_network_operator *list;
|
struct ofono_network_operator *list;
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
@ -386,16 +387,16 @@ static void cops_list_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
g_free(list);
|
g_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_list_operators(struct ofono_modem *modem, ofono_operator_list_cb_t cb,
|
static void at_list_operators(struct ofono_netreg *netreg,
|
||||||
void *data)
|
ofono_netreg_operator_list_cb_t cb, void *data)
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
struct cb_data *cbd = cb_data_new(modem, cb, data);
|
struct cb_data *cbd = cb_data_new(NULL, cb, data);
|
||||||
|
|
||||||
if (!cbd)
|
if (!cbd)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_at_chat_send(at->parser, "AT+COPS=?", cops_prefix,
|
if (g_at_chat_send(nd->chat, "AT+COPS=?", cops_prefix,
|
||||||
cops_list_cb, cbd, g_free) > 0)
|
cops_list_cb, cbd, g_free) > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -412,7 +413,7 @@ error:
|
||||||
static void register_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
static void register_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
ofono_generic_cb_t cb = cbd->cb;
|
ofono_netreg_register_cb_t cb = cbd->cb;
|
||||||
struct ofono_error error;
|
struct ofono_error error;
|
||||||
|
|
||||||
dump_response("register_cb", ok, result);
|
dump_response("register_cb", ok, result);
|
||||||
|
@ -421,16 +422,16 @@ static void register_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
cb(&error, cbd->data);
|
cb(&error, cbd->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_register_auto(struct ofono_modem *modem, ofono_generic_cb_t cb,
|
static void at_register_auto(struct ofono_netreg *netreg,
|
||||||
void *data)
|
ofono_netreg_register_cb_t cb, void *data)
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
struct cb_data *cbd = cb_data_new(modem, cb, data);
|
struct cb_data *cbd = cb_data_new(NULL, cb, data);
|
||||||
|
|
||||||
if (!cbd)
|
if (!cbd)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_at_chat_send(at->parser, "AT+COPS=0", none_prefix,
|
if (g_at_chat_send(nd->chat, "AT+COPS=0", none_prefix,
|
||||||
register_cb, cbd, g_free) > 0)
|
register_cb, cbd, g_free) > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -444,12 +445,12 @@ error:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_register_manual(struct ofono_modem *modem,
|
static void at_register_manual(struct ofono_netreg *netreg,
|
||||||
const struct ofono_network_operator *oper,
|
const struct ofono_network_operator *oper,
|
||||||
ofono_generic_cb_t cb, void *data)
|
ofono_netreg_register_cb_t cb, void *data)
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
struct cb_data *cbd = cb_data_new(modem, cb, data);
|
struct cb_data *cbd = cb_data_new(NULL, cb, data);
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
if (!cbd)
|
if (!cbd)
|
||||||
|
@ -457,7 +458,7 @@ static void at_register_manual(struct ofono_modem *modem,
|
||||||
|
|
||||||
sprintf(buf, "AT+COPS=1,2,\"%s%s\"", oper->mcc, oper->mnc);
|
sprintf(buf, "AT+COPS=1,2,\"%s%s\"", oper->mcc, oper->mnc);
|
||||||
|
|
||||||
if (g_at_chat_send(at->parser, buf, none_prefix,
|
if (g_at_chat_send(nd->chat, buf, none_prefix,
|
||||||
register_cb, cbd, g_free) > 0)
|
register_cb, cbd, g_free) > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -471,16 +472,16 @@ error:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_deregister(struct ofono_modem *modem, ofono_generic_cb_t cb,
|
static void at_deregister(struct ofono_netreg *netreg,
|
||||||
void *data)
|
ofono_netreg_register_cb_t cb, void *data)
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
struct cb_data *cbd = cb_data_new(modem, cb, data);
|
struct cb_data *cbd = cb_data_new(NULL, cb, data);
|
||||||
|
|
||||||
if (!cbd)
|
if (!cbd)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_at_chat_send(at->parser, "AT+COPS=2", none_prefix,
|
if (g_at_chat_send(nd->chat, "AT+COPS=2", none_prefix,
|
||||||
register_cb, cbd, g_free) > 0)
|
register_cb, cbd, g_free) > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -496,7 +497,7 @@ error:
|
||||||
|
|
||||||
static void csq_notify(GAtResult *result, gpointer user_data)
|
static void csq_notify(GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct ofono_modem *modem = user_data;
|
struct ofono_netreg *netreg = user_data;
|
||||||
int strength;
|
int strength;
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
|
|
||||||
|
@ -517,13 +518,13 @@ static void csq_notify(GAtResult *result, gpointer user_data)
|
||||||
else
|
else
|
||||||
strength = strength * 100 / 31;
|
strength = strength * 100 / 31;
|
||||||
|
|
||||||
ofono_signal_strength_notify(modem, strength);
|
ofono_netreg_strength_notify(netreg, strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void csq_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
static void csq_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct cb_data *cbd = user_data;
|
struct cb_data *cbd = user_data;
|
||||||
ofono_signal_strength_cb_t cb = cbd->cb;
|
ofono_netreg_strength_cb_t cb = cbd->cb;
|
||||||
int strength;
|
int strength;
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
struct ofono_error error;
|
struct ofono_error error;
|
||||||
|
@ -557,16 +558,16 @@ static void csq_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
cb(&error, strength, cbd->data);
|
cb(&error, strength, cbd->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_signal_strength(struct ofono_modem *modem,
|
static void at_signal_strength(struct ofono_netreg *netreg,
|
||||||
ofono_signal_strength_cb_t cb, void *data)
|
ofono_netreg_strength_cb_t cb, void *data)
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
struct cb_data *cbd = cb_data_new(modem, cb, data);
|
struct cb_data *cbd = cb_data_new(NULL, cb, data);
|
||||||
|
|
||||||
if (!cbd)
|
if (!cbd)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (g_at_chat_send(at->parser, "AT+CSQ", csq_prefix,
|
if (g_at_chat_send(nd->chat, "AT+CSQ", csq_prefix,
|
||||||
csq_cb, cbd, g_free) > 0)
|
csq_cb, cbd, g_free) > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -582,7 +583,7 @@ error:
|
||||||
|
|
||||||
static void creg_notify(GAtResult *result, gpointer user_data)
|
static void creg_notify(GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct ofono_modem *modem = user_data;
|
struct ofono_netreg *netreg = user_data;
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
int status;
|
int status;
|
||||||
int lac = -1, ci = -1, tech = -1;
|
int lac = -1, ci = -1, tech = -1;
|
||||||
|
@ -612,61 +613,73 @@ static void creg_notify(GAtResult *result, gpointer user_data)
|
||||||
out:
|
out:
|
||||||
ofono_debug("creg_notify: %d, %d, %d, %d", status, lac, ci, tech);
|
ofono_debug("creg_notify: %d, %d, %d, %d", status, lac, ci, tech);
|
||||||
|
|
||||||
ofono_network_registration_notify(modem, status, lac, ci, tech);
|
ofono_netreg_status_notify(netreg, status, lac, ci, tech);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ofono_network_registration_ops ops = {
|
static void at_network_registration_initialized(gboolean ok, GAtResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
struct ofono_netreg *netreg = user_data;
|
||||||
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
ofono_error("Unable to initialize Network Registration");
|
||||||
|
ofono_netreg_remove(netreg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_at_chat_register(nd->chat, "+CREG:",
|
||||||
|
creg_notify, FALSE, netreg, NULL);
|
||||||
|
g_at_chat_register(nd->chat, "+CSQ:",
|
||||||
|
csq_notify, FALSE, netreg, NULL);
|
||||||
|
|
||||||
|
ofono_netreg_register(netreg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int at_netreg_probe(struct ofono_netreg *netreg)
|
||||||
|
{
|
||||||
|
GAtChat *chat = ofono_netreg_get_data(netreg);
|
||||||
|
struct netreg_data *nd;
|
||||||
|
|
||||||
|
nd = g_new0(struct netreg_data, 1);
|
||||||
|
|
||||||
|
nd->chat = chat;
|
||||||
|
ofono_netreg_set_data(netreg, nd);
|
||||||
|
|
||||||
|
g_at_chat_send(chat, "AT+CREG=2", NULL,
|
||||||
|
at_network_registration_initialized,
|
||||||
|
netreg, NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int at_netreg_remove(struct ofono_netreg *netreg)
|
||||||
|
{
|
||||||
|
struct netreg_data *nd = ofono_netreg_get_data(netreg);
|
||||||
|
|
||||||
|
g_free(nd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct ofono_netreg_driver driver = {
|
||||||
|
.name = "generic_at",
|
||||||
|
.probe = at_netreg_probe,
|
||||||
|
.remove = at_netreg_remove,
|
||||||
.registration_status = at_registration_status,
|
.registration_status = at_registration_status,
|
||||||
.current_operator = at_current_operator,
|
.current_operator = at_current_operator,
|
||||||
.list_operators = at_list_operators,
|
.list_operators = at_list_operators,
|
||||||
.register_auto = at_register_auto,
|
.register_auto = at_register_auto,
|
||||||
.register_manual = at_register_manual,
|
.register_manual = at_register_manual,
|
||||||
.deregister = at_deregister,
|
.deregister = at_deregister,
|
||||||
.signal_strength = at_signal_strength,
|
.strength = at_signal_strength,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void at_network_registration_initialized(gboolean ok, GAtResult *result,
|
void at_netreg_init()
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
struct ofono_modem *modem = user_data;
|
ofono_netreg_driver_register(&driver);
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
ofono_error("Unable to initialize Network Registration");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_at_chat_register(at->parser, "+CREG:",
|
|
||||||
creg_notify, FALSE, modem, NULL);
|
|
||||||
g_at_chat_register(at->parser, "+CSQ:",
|
|
||||||
csq_notify, FALSE, modem, NULL);
|
|
||||||
|
|
||||||
ofono_network_registration_register(modem, &ops);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void at_network_registration_init(struct ofono_modem *modem)
|
void at_netreg_exit()
|
||||||
{
|
{
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
ofono_netreg_driver_unregister(&driver);
|
||||||
|
|
||||||
at->netreg = g_try_new0(struct netreg_data, 1);
|
|
||||||
|
|
||||||
if (!at->netreg)
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_at_chat_send(at->parser, "AT+CREG=2", NULL,
|
|
||||||
at_network_registration_initialized,
|
|
||||||
modem, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void at_network_registration_exit(struct ofono_modem *modem)
|
|
||||||
{
|
|
||||||
struct at_data *at = ofono_modem_get_userdata(modem);
|
|
||||||
|
|
||||||
if (!at->netreg)
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_free(at->netreg);
|
|
||||||
at->netreg = NULL;
|
|
||||||
|
|
||||||
ofono_network_registration_unregister(modem);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue