summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAki Niemi <aki.niemi@nokia.com>2011-02-18 16:13:06 +0200
committerAki Niemi <aki.niemi@nokia.com>2011-02-18 16:17:14 +0200
commit5c84a23515a1ac2ee053e3bbce45312aecf6afd4 (patch)
tree81447299c69b31e7f1b8091b23f478b025ff4ede /drivers
parent2141228651027d5321980dbac24869aa1700250e (diff)
downloadofono-5c84a23515a1ac2ee053e3bbce45312aecf6afd4.tar.bz2
isimodem: Refactor gprs-context driver
Use stack allocation for padding, and simplify message sending and failure handling.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/isimodem/gprs-context.c102
1 files changed, 46 insertions, 56 deletions
diff --git a/drivers/isimodem/gprs-context.c b/drivers/isimodem/gprs-context.c
index f458fcc3..bbf7ca92 100644
--- a/drivers/isimodem/gprs-context.c
+++ b/drivers/isimodem/gprs-context.c
@@ -347,50 +347,44 @@ static void send_context_authenticate(GIsiClient *client, void *opaque)
struct context_data *cd = opaque;
size_t username_len = strlen(cd->username);
size_t password_len = strlen(cd->password);
- size_t sb_user_info_len = (3 + username_len + 3) & ~3;
- size_t fill_sb_user_info_count =
- sb_user_info_len - (3 + username_len);
- uint8_t *fill_sb_user_info_data =
- g_try_malloc0(fill_sb_user_info_count);
+
+ /* Pad the fields to the next 32bit boundary */
+ size_t sb_userinfo_len = (3 + username_len + 3) & ~3;
+ uint8_t userinfo_pad[sb_userinfo_len - (3 + username_len)];
+
size_t sb_password_info_len = (3 + password_len + 3) & ~3;
- size_t fill_sb_password_info_count =
- sb_user_info_len - (3 + password_len);
- uint8_t *fill_sb_password_info_data =
- g_try_malloc0(fill_sb_password_info_count);
+ uint8_t password_pad[sb_password_info_len - (3 + password_len)];
- const unsigned char top[] = {
+ const uint8_t top[] = {
GPDS_CONTEXT_AUTH_REQ,
cd->handle,
2, /* sub blocks */
GPDS_USER_NAME_INFO,
- sb_user_info_len,
+ sb_userinfo_len,
username_len,
/* Username goes here */
+ /* Possible padding goes here */
};
- const unsigned char bottom[] = {
+ const uint8_t bottom[] = {
GPDS_PASSWORD_INFO,
sb_password_info_len,
password_len,
/* Password goes here */
+ /* Possible padding goes here */
};
const struct iovec iov[6] = {
{ (uint8_t *)top, sizeof(top) },
{ cd->username, username_len },
- { fill_sb_user_info_data, fill_sb_user_info_count },
+ { userinfo_pad, sizeof(userinfo_pad) },
{ (uint8_t *)bottom, sizeof(bottom) },
{ cd->password, password_len },
- { fill_sb_password_info_data, fill_sb_password_info_count},
+ { password_pad, sizeof(password_pad) },
};
- if (fill_sb_user_info_data == NULL
- && fill_sb_user_info_count > 0)
- gprs_up_fail(cd);
-
- if (fill_sb_password_info_data == NULL
- && fill_sb_password_info_count > 0)
- gprs_up_fail(cd);
+ memset(userinfo_pad, 0, sizeof(userinfo_pad));
+ memset(password_pad, 0, sizeof(password_pad));
if (!g_isi_client_vsend(client, iov, 6, context_auth_cb, cd, NULL))
gprs_up_fail(cd);
@@ -414,42 +408,38 @@ static void link_conf_cb(const GIsiMessage *msg, void *opaque)
struct context_data *cd = opaque;
size_t apn_len = strlen(cd->apn);
size_t sb_apn_info_len = (3 + apn_len + 3) & ~3;
- size_t fill_count = sb_apn_info_len - (3 + apn_len);
- uint8_t *fill_data = g_try_malloc0(fill_count);
-
- if (fill_data == NULL && fill_count > 0)
- return gprs_up_fail(cd);
-
- if (check_resp(msg, GPDS_LL_CONFIGURE_RESP, 2, cd, gprs_up_fail)) {
-
- const unsigned char msg[] = {
- GPDS_CONTEXT_CONFIGURE_REQ,
- cd->handle, /* context ID */
- cd->type, /* PDP type */
- GPDS_CONT_TYPE_NORMAL,
- cd->handle, /* primary context ID */
- 0x00, /* filler */
- 2, /* sub blocks */
- GPDS_DNS_ADDRESS_REQ_INFO,
- 4, /* subblock length */
- 0, 0, /* padding */
- GPDS_APN_INFO,
- sb_apn_info_len,
- apn_len,
- };
-
- const struct iovec iov[3] = {
- { (uint8_t *)msg, sizeof(msg) },
- { cd->apn, apn_len },
- { fill_data, fill_count}
- };
-
- if (!g_isi_client_vsend_with_timeout(cd->client, iov, 3,
- GPDS_TIMEOUT, context_conf_cb, cd, NULL))
- return gprs_up_fail(cd);
- } else
- return gprs_up_fail(cd);
+ size_t apn_pad[sb_apn_info_len - (3 + apn_len)];
+
+ const uint8_t req[] = {
+ GPDS_CONTEXT_CONFIGURE_REQ,
+ cd->handle, /* context ID */
+ cd->type, /* PDP type */
+ GPDS_CONT_TYPE_NORMAL,
+ cd->handle, /* primary context ID */
+ 0x00, /* filler */
+ 2, /* sub blocks */
+ GPDS_DNS_ADDRESS_REQ_INFO,
+ 4, /* subblock length */
+ 0, 0, /* padding */
+ GPDS_APN_INFO,
+ sb_apn_info_len,
+ apn_len,
+ /* Possible padding goes here */
+ };
+
+ const struct iovec iov[3] = {
+ { (uint8_t *)req, sizeof(req) },
+ { cd->apn, apn_len },
+ { apn_pad, sizeof(apn_pad) },
+ };
+
+ memset(apn_pad, 0, sizeof(apn_pad));
+ if (!check_resp(msg, GPDS_LL_CONFIGURE_RESP, 2, cd, gprs_up_fail))
+ return;
+
+ if (!g_isi_client_vsend(cd->client, iov, 3, context_conf_cb, cd, NULL))
+ gprs_up_fail(cd);
}
static void create_context_cb(const GIsiMessage *msg, void *opaque)