Strings in mbim messages have to follow these formatting rules:
- 4 byte alignment, padded if not.
- utf-16 little endian.
Fixes:
- mbim connect fails with more than 1 string parameter (apn/user/pass)
when they are not 4 byte aligned.
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
int
mbim_encode_string(struct mbim_string *str, char *in)
{
- int l = strlen(in);
- int s = mbim_add_payload(l * 2);
+ const int l = strlen(in);
+ const int utf16_len = l * 2;
+ const int pad_len = utf16_len % 4;
+ const int s = mbim_add_payload(utf16_len + pad_len);
uint8_t *p = &payload_buffer[s];
int i;
return -1;
str->offset = htole32(s);
- str->length = htole32(l * 2);
+ str->length = htole32(utf16_len);
+
for (i = 0; i < l; i++)
p[i * 2] = in[i];
return 0;
}
-
char *
mbim_get_string(struct mbim_string *str, char *in)
{