Skip to content

Commit

Permalink
Add mgos_pppos_get_{imei,imsi}
Browse files Browse the repository at this point in the history
CL: Add mgos_pppos_get_{imei,imsi}

PUBLISHED_FROM=a74cc4b51581ca326ad600f5d72f93611043b4f4
  • Loading branch information
cpq authored and cesantabot committed Feb 5, 2019
1 parent 8a244b8 commit 4063ce0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 2 additions & 3 deletions include/mgos_pppos.h
Expand Up @@ -47,12 +47,11 @@ struct mgos_pppos_cmd_resp {
};

bool mgos_pppos_send_cmd(int iface, const char *req);

bool mgos_pppos_create(const struct mgos_config_pppos *cfg, int if_instance);

bool mgos_pppos_connect(int if_instance);

bool mgos_pppos_disconnect(int if_instance);
struct mg_str mgos_pppos_get_imei(int if_instance);
struct mg_str mgos_pppos_get_imsi(int if_instance);

#ifdef __cplusplus
}
Expand Down
24 changes: 22 additions & 2 deletions src/mgos_pppos.c
Expand Up @@ -22,9 +22,9 @@
#include "common/mg_str.h"
#include "common/queue.h"

#include "lwip/tcpip.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
#include "netif/ppp/ppp.h"
#include "netif/ppp/pppapi.h"
#include "netif/ppp/pppos.h"
Expand Down Expand Up @@ -95,7 +95,11 @@ static SLIST_HEAD(s_pds, mgos_pppos_data) s_pds = SLIST_HEAD_INITIALIZER(s_pds);
/* If we fail to communicate with the modem at the specified rate,
* we will try these (with no flow control), in this order. */
static const int s_baud_rates[] = {0 /* first we try the confgured rate */,
9600, 115200, 230400, 460800, 921600};
9600,
115200,
230400,
460800,
921600};

static void mgos_pppos_try_baud_rate(struct mgos_pppos_data *pd) {
struct mgos_uart_config ucfg;
Expand Down Expand Up @@ -680,6 +684,22 @@ bool mgos_pppos_disconnect(int if_instance) {
return false;
}

struct mg_str mgos_pppos_get_imsi(int if_instance) {
struct mgos_pppos_data *pd;
SLIST_FOREACH(pd, &s_pds, next) {
if (pd->if_instance == if_instance) return mg_strdup(pd->cimi_resp);
}
return mg_mk_str_n(NULL, 0);
}

struct mg_str mgos_pppos_get_imei(int if_instance) {
struct mgos_pppos_data *pd;
SLIST_FOREACH(pd, &s_pds, next) {
if (pd->if_instance == if_instance) return mg_strdup(pd->ati_resp);
}
return mg_mk_str_n(NULL, 0);
}

bool mgos_pppos_create(const struct mgos_config_pppos *cfg, int if_instance) {
struct mgos_uart_config ucfg;
mgos_uart_config_set_defaults(cfg->uart_no, &ucfg);
Expand Down

0 comments on commit 4063ce0

Please sign in to comment.