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); - 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); - const unsigned char top[] = { + /* 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; + uint8_t password_pad[sb_password_info_len - (3 + password_len)]; + + 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); + size_t apn_pad[sb_apn_info_len - (3 + apn_len)]; - if (fill_data == NULL && fill_count > 0) - return gprs_up_fail(cd); + 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 */ + }; - if (check_resp(msg, GPDS_LL_CONFIGURE_RESP, 2, cd, gprs_up_fail)) { + const struct iovec iov[3] = { + { (uint8_t *)req, sizeof(req) }, + { cd->apn, apn_len }, + { apn_pad, sizeof(apn_pad) }, + }; - 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, - }; + memset(apn_pad, 0, sizeof(apn_pad)); - 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); + 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)