diff options
Diffstat (limited to 'src/libgsmd')
-rw-r--r-- | src/libgsmd/lgsm_internals.h | 2 | ||||
-rw-r--r-- | src/libgsmd/libgsmd_event.c | 7 | ||||
-rw-r--r-- | src/libgsmd/libgsmd_network.c | 45 |
3 files changed, 47 insertions, 7 deletions
diff --git a/src/libgsmd/lgsm_internals.h b/src/libgsmd/lgsm_internals.h index bf1f4a2..94421fa 100644 --- a/src/libgsmd/lgsm_internals.h +++ b/src/libgsmd/lgsm_internals.h @@ -2,10 +2,12 @@ #define _LGSM_INTERNALS_H #include <gsmd/usock.h> +#include <libgsmd/misc.h> struct lgsm_handle { int fd; lgsm_msg_handler *handler[__NUM_GSMD_MSGS]; + enum lgsm_netreg_state netreg_state; }; int lgsm_send(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh); diff --git a/src/libgsmd/libgsmd_event.c b/src/libgsmd/libgsmd_event.c index c751cad..777edd8 100644 --- a/src/libgsmd/libgsmd_event.c +++ b/src/libgsmd/libgsmd_event.c @@ -63,6 +63,12 @@ static int evt_demux_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh gmh->msg_subtype >= __NUM_GSMD_EVT) return -EINVAL; + switch (gmh->msg_subtype) { + case GSMD_EVT_NETREG: + lh->netreg_state = aux->u.netreg.state; + break; + } + if (evt_handlers[gmh->msg_subtype]) return evt_handlers[gmh->msg_subtype](lh, gmh->msg_subtype, aux); else @@ -71,6 +77,7 @@ static int evt_demux_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh int lgsm_evt_init(struct lgsm_handle *lh) { + lh->netreg_state = LGSM_NETREG_ST_NOTREG; return lgsm_register_handler(lh, GSMD_MSG_EVENT, &evt_demux_msghandler); } diff --git a/src/libgsmd/libgsmd_network.c b/src/libgsmd/libgsmd_network.c index 800b58c..9a21fb5 100644 --- a/src/libgsmd/libgsmd_network.c +++ b/src/libgsmd/libgsmd_network.c @@ -32,18 +32,49 @@ #include "lgsm_internals.h" -int lgsm_netreg_register(struct lgsm_handle *lh, int oper) +/* Get the current network registration status */ +int lgsm_get_netreg_state(struct lgsm_handle *lh, + enum lgsm_netreg_state *state) { - /* FIXME: implement oper selection */ - return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_REGISTER); + *state = lh->netreg_state; } -int lgsm_signal_quality(struct lgsm_handle *lh) +int lgsm_oper_get(struct lgsm_handle *lh) { - return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_SIGQ_GET); + return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_OPER_GET); } -int lgsmd_operator_name(struct lgsm_handle *lh) +int lgsm_opers_get(struct lgsm_handle *lh) { - return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_OPER_GET); + return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_OPER_LIST); +} + +int lgsm_netreg_register(struct lgsm_handle *lh, gsmd_oper_numeric oper) +{ + struct gsmd_msg_hdr *gmh; + + gmh = lgsm_gmh_fill(GSMD_MSG_NETWORK, GSMD_NETWORK_REGISTER, + sizeof(gsmd_oper_numeric)); + if (!gmh) + return -ENOMEM; + + memcpy(gmh->data, oper, sizeof(gsmd_oper_numeric)); + + if (lgsm_send(lh, gmh) < gmh->len + sizeof(*gmh)) { + lgsm_gmh_free(gmh); + return -EIO; + } + + lgsm_gmh_free(gmh); + return 0; +} + +int lgsm_netreg_deregister(struct lgsm_handle *lh) +{ + return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_DEREGISTER); +} + +int lgsm_signal_quality(struct lgsm_handle *lh) +{ + return lgsm_send_simple(lh, GSMD_MSG_NETWORK, GSMD_NETWORK_SIGQ_GET); } |