mirror of git://git.sysmocom.de/ofono
stemodem: Fix for error handling, memleak and changed some defines
* renamed MAX_LEN to IP_ADDR_LEN * removed memory leak from unneeded strdup when parsing xml response. * better handling of AT error responses * reduced number of caif interfaces to 4
This commit is contained in:
parent
4a82cb0233
commit
2f9af8c105
|
@ -47,9 +47,9 @@
|
||||||
#include "caif_socket.h"
|
#include "caif_socket.h"
|
||||||
#include "if_caif.h"
|
#include "if_caif.h"
|
||||||
|
|
||||||
#define MAX_CAIF_DEVICES 7
|
#define MAX_CAIF_DEVICES 4
|
||||||
#define MAX_DNS 2
|
#define MAX_DNS 2
|
||||||
#define MAX_ELEM 20
|
#define IP_ADDR_LEN 20
|
||||||
|
|
||||||
#define AUTH_BUF_LENGTH (OFONO_GPRS_MAX_USERNAME_LENGTH + \
|
#define AUTH_BUF_LENGTH (OFONO_GPRS_MAX_USERNAME_LENGTH + \
|
||||||
OFONO_GPRS_MAX_PASSWORD_LENGTH + 128)
|
OFONO_GPRS_MAX_PASSWORD_LENGTH + 128)
|
||||||
|
@ -73,13 +73,13 @@ struct conn_info {
|
||||||
|
|
||||||
struct eppsd_response {
|
struct eppsd_response {
|
||||||
char *current;
|
char *current;
|
||||||
char ip_address[MAX_ELEM];
|
char ip_address[IP_ADDR_LEN];
|
||||||
char subnet_mask[MAX_ELEM];
|
char subnet_mask[IP_ADDR_LEN];
|
||||||
char mtu[MAX_ELEM];
|
char mtu[IP_ADDR_LEN];
|
||||||
char default_gateway[MAX_ELEM];
|
char default_gateway[IP_ADDR_LEN];
|
||||||
char dns_server1[MAX_ELEM];
|
char dns_server1[IP_ADDR_LEN];
|
||||||
char dns_server2[MAX_ELEM];
|
char dns_server2[IP_ADDR_LEN];
|
||||||
char p_cscf_server[MAX_ELEM];
|
char p_cscf_server[IP_ADDR_LEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void start_element_handler(GMarkupParseContext *context,
|
static void start_element_handler(GMarkupParseContext *context,
|
||||||
|
@ -122,8 +122,8 @@ static void text_handler(GMarkupParseContext *context,
|
||||||
struct eppsd_response *rsp = user_data;
|
struct eppsd_response *rsp = user_data;
|
||||||
|
|
||||||
if (rsp->current) {
|
if (rsp->current) {
|
||||||
strncpy(rsp->current, text, MAX_ELEM);
|
strncpy(rsp->current, text, IP_ADDR_LEN);
|
||||||
rsp->current[MAX_ELEM] = 0;
|
rsp->current[IP_ADDR_LEN] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,12 +191,16 @@ static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
|
||||||
ofono_gprs_context_cb_t cb = cbd->cb;
|
ofono_gprs_context_cb_t cb = cbd->cb;
|
||||||
struct ofono_gprs_context *gc = cbd->user;
|
struct ofono_gprs_context *gc = cbd->user;
|
||||||
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
|
||||||
struct ofono_error error;
|
|
||||||
struct conn_info *conn;
|
struct conn_info *conn;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
|
||||||
if (!ok)
|
if (!ok) {
|
||||||
goto error;
|
struct ofono_error error;
|
||||||
|
|
||||||
|
decode_at_error(&error, g_at_result_final_response(result));
|
||||||
|
cb(&error, cbd->data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
l = g_slist_find_custom(g_caif_devices,
|
l = g_slist_find_custom(g_caif_devices,
|
||||||
GUINT_TO_POINTER(gcd->active_context),
|
GUINT_TO_POINTER(gcd->active_context),
|
||||||
|
@ -217,9 +221,6 @@ static void ste_eppsd_down_cb(gboolean ok, GAtResult *result,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->cid = 0;
|
conn->cid = 0;
|
||||||
|
|
||||||
decode_at_error(&error, g_at_result_final_response(result));
|
|
||||||
cb(&error, cbd->data);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -237,7 +238,7 @@ static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
GSList *l;
|
GSList *l;
|
||||||
int i;
|
int i;
|
||||||
gsize length;
|
gsize length;
|
||||||
char *res_string;
|
const char *res_string;
|
||||||
const char *dns[MAX_DNS + 1];
|
const char *dns[MAX_DNS + 1];
|
||||||
struct eppsd_response rsp;
|
struct eppsd_response rsp;
|
||||||
GMarkupParseContext *context = NULL;
|
GMarkupParseContext *context = NULL;
|
||||||
|
@ -255,8 +256,15 @@ static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
|
|
||||||
conn = l->data;
|
conn = l->data;
|
||||||
|
|
||||||
if (!ok)
|
if (!ok) {
|
||||||
goto error;
|
struct ofono_error error;
|
||||||
|
|
||||||
|
conn->cid = 0;
|
||||||
|
gcd->active_context = 0;
|
||||||
|
decode_at_error(&error, g_at_result_final_response(result));
|
||||||
|
cb(&error, NULL, 0, NULL, NULL, NULL, NULL, cbd->data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
rsp.current = NULL;
|
rsp.current = NULL;
|
||||||
context = g_markup_parse_context_new(&parser, 0, &rsp, NULL);
|
context = g_markup_parse_context_new(&parser, 0, &rsp, NULL);
|
||||||
|
@ -266,7 +274,7 @@ static void ste_eppsd_up_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
|
|
||||||
for (i = 0; i < g_at_result_num_response_lines(result); i++) {
|
for (i = 0; i < g_at_result_num_response_lines(result); i++) {
|
||||||
g_at_result_iter_next(&iter, NULL);
|
g_at_result_iter_next(&iter, NULL);
|
||||||
res_string = strdup(g_at_result_iter_raw_line(&iter));
|
res_string = g_at_result_iter_raw_line(&iter);
|
||||||
length = strlen(res_string);
|
length = strlen(res_string);
|
||||||
|
|
||||||
if (!g_markup_parse_context_parse(context, res_string,
|
if (!g_markup_parse_context_parse(context, res_string,
|
||||||
|
@ -326,7 +334,6 @@ static void ste_cgdcont_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
struct ofono_error error;
|
struct ofono_error error;
|
||||||
|
|
||||||
gcd->active_context = 0;
|
gcd->active_context = 0;
|
||||||
|
|
||||||
decode_at_error(&error, g_at_result_final_response(result));
|
decode_at_error(&error, g_at_result_final_response(result));
|
||||||
cb(&error, NULL, 0, NULL, NULL, NULL, NULL, cbd->data);
|
cb(&error, NULL, 0, NULL, NULL, NULL, NULL, cbd->data);
|
||||||
return;
|
return;
|
||||||
|
@ -389,7 +396,7 @@ static void ste_gprs_activate_primary(struct ofono_gprs_context *gc,
|
||||||
* Set username and password, this should be done after CGDCONT
|
* Set username and password, this should be done after CGDCONT
|
||||||
* or an error can occur. We don't bother with error checking
|
* or an error can occur. We don't bother with error checking
|
||||||
* here
|
* here
|
||||||
* */
|
*/
|
||||||
snprintf(buf, sizeof(buf), "AT*EIAAUW=%d,1,\"%s\",\"%s\"",
|
snprintf(buf, sizeof(buf), "AT*EIAAUW=%d,1,\"%s\",\"%s\"",
|
||||||
ctx->cid, ctx->username, ctx->password);
|
ctx->cid, ctx->username, ctx->password);
|
||||||
|
|
||||||
|
@ -398,6 +405,7 @@ static void ste_gprs_activate_primary(struct ofono_gprs_context *gc,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
gcd->active_context = 0;
|
||||||
g_free(cbd);
|
g_free(cbd);
|
||||||
|
|
||||||
CALLBACK_WITH_FAILURE(cb, NULL, 0, NULL, NULL, NULL, NULL, data);
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, NULL, NULL, NULL, NULL, data);
|
||||||
|
|
Loading…
Reference in New Issue