#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include <libubox/utils.h>
#include <libubox/uloop.h>
if (le32toh(state->readyinfo) & MBIM_READY_INFO_FLAG_PROTECT_UNIQUE_ID)
printf(" dont display subscriberID: 1\n");
for (nr = 0; nr < le32toh(state->telephonenumberscount); nr++) {
- struct mbim_string *str = buffer + le32toh(state->telephonenumbers) + (nr * sizeof(struct mbim_string));
+ struct mbim_string *str = (void *)&state->telephonenumbers + (nr * sizeof(struct mbim_string));
char *number = mbim_get_string(str, buffer);
printf(" number: %s\n", number);
}
mbim_enum_string(mbim_nw_error_values, le32toh(ps->nwerror)));
printf(" packetservicestate: %04X - %s\n", le32toh(ps->packetservicestate),
mbim_enum_string(mbim_packet_service_state_values, le32toh(ps->packetservicestate)));
- printf(" uplinkspeed: %"PRIu64"\n", le64toh(ps->uplinkspeed));
- printf(" downlinkspeed: %"PRIu64"\n", le64toh(ps->downlinkspeed));
+ printf(" uplinkspeed: %"PRIu64"\n", (uint64_t) le64toh(ps->uplinkspeed));
+ printf(" downlinkspeed: %"PRIu64"\n", (uint64_t) le64toh(ps->downlinkspeed));
if (MBIM_PACKET_SERVICE_STATE_ATTACHED == le32toh(ps->packetservicestate))
return 0;
mbim_config_response(void *buffer, int len)
{
struct mbim_basic_connect_ip_configuration_r *ip = (struct mbim_basic_connect_ip_configuration_r *) buffer;
- char ipv4[16];
+ char out[40];
int i;
+ uint32_t offset;
if (len < sizeof(struct mbim_basic_connect_ip_configuration_r)) {
fprintf(stderr, "message not long enough\n");
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS)
for (i = 0; i < le32toh(ip->ipv4addresscount); i++) {
- mbim_get_ipv4(buffer, ipv4, ip->ipv4address + (i * 4));
- printf(" ipv4address: %s\n", ipv4);
+ offset = le32toh(ip->ipv4address) + (i * 4);
+ mbim_get_ipv4(buffer, out, 4 + offset);
+ printf(" ipv4address: %s/%d\n", out, mbim_get_int(buffer, offset));
}
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) {
- mbim_get_ipv4(buffer, ipv4, ip->ipv4gateway);
- printf(" ipv4gateway: %s\n", ipv4);
+ mbim_get_ipv4(buffer, out, le32toh(ip->ipv4gateway));
+ printf(" ipv4gateway: %s\n", out);
}
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
printf(" ipv4mtu: %d\n", le32toh(ip->ipv4mtu));
if (le32toh(ip->ipv4configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS)
for (i = 0; i < le32toh(ip->ipv4dnsservercount); i++) {
- mbim_get_ipv4(buffer, ipv4, ip->ipv4dnsserver + (i * 4));
- printf(" ipv4dnsserver: %s\n", ipv4);
+ mbim_get_ipv4(buffer, out, le32toh(ip->ipv4dnsserver) + (i * 4));
+ printf(" ipv4dnsserver: %s\n", out);
}
- printf(" ipv6configurationavailable: %04X\n", le32toh(ip->ipv6configurationavailable));
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS)
+ for (i = 0; i < le32toh(ip->ipv6addresscount); i++) {
+ offset = le32toh(ip->ipv6address) + (i * 16);
+ mbim_get_ipv6(buffer, out, 4 + offset);
+ printf(" ipv6address: %s/%d\n", out, mbim_get_int(buffer, offset));
+ }
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) {
+ mbim_get_ipv6(buffer, out, le32toh(ip->ipv6gateway));
+ printf(" ipv6gateway: %s\n", out);
+ }
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
+ printf(" ipv6mtu: %d\n", le32toh(ip->ipv6mtu));
+ if (le32toh(ip->ipv6configurationavailable) & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS)
+ for (i = 0; i < le32toh(ip->ipv6dnsservercount); i++) {
+ mbim_get_ipv6(buffer, out, le32toh(ip->ipv6dnsserver) + (i * 16));
+ printf(" ipv6dnsserver: %s\n", out);
+ }
return 0;
}
static int
mbim_connect_request(void)
{
+ char *apn;
struct mbim_basic_connect_connect_s *c =
(struct mbim_basic_connect_connect_s *) mbim_setup_command_msg(basic_connect,
MBIM_MESSAGE_COMMAND_TYPE_SET, MBIM_CMD_BASIC_CONNECT_CONNECT,
c->activationcommand = htole32(MBIM_ACTIVATION_COMMAND_ACTIVATE);
c->iptype = htole32(MBIM_CONTEXT_IP_TYPE_DEFAULT);
memcpy(c->contexttype, uuid_context_type_internet, 16);
- if (_argc > 0)
- mbim_encode_string(&c->accessstring, *_argv);
-
+ if (_argc > 0) {
+ apn = index(*_argv, ':');
+ if (!apn) {
+ apn = *_argv;
+ } else {
+ apn[0] = 0;
+ apn++;
+ if (!strcmp(*_argv, "ipv4"))
+ c->iptype = htole32(MBIM_CONTEXT_IP_TYPE_IPV4);
+ else if (!strcmp(*_argv, "ipv6"))
+ c->iptype = htole32(MBIM_CONTEXT_IP_TYPE_IPV6);
+ else if (!strcmp(*_argv, "ipv4v6"))
+ c->iptype = htole32(MBIM_CONTEXT_IP_TYPE_IPV4V6);
+ }
+ mbim_encode_string(&c->accessstring, apn);
+ }
+ if (_argc > 3) {
+ if (!strcmp(_argv[1], "pap"))
+ c->authprotocol = htole32(MBIM_AUTH_PROTOCOL_PAP);
+ else if (!strcmp(_argv[1], "chap"))
+ c->authprotocol = htole32(MBIM_AUTH_PROTOCOL_CHAP);
+ else if (!strcmp(_argv[1], "mschapv2"))
+ c->authprotocol = htole32(MBIM_AUTH_PROTOCOL_MSCHAPV2);
+
+ if (c->authprotocol) {
+ mbim_encode_string(&c->username, _argv[2]);
+ mbim_encode_string(&c->password, _argv[3]);
+ }
+ }
return mbim_send_command_msg();
}
return mbim_send_command_msg();
}
+static char*
+mbim_pin_sanitize(char *pin)
+{
+ char *p;
+
+ while (*pin && !isdigit(*pin))
+ pin++;
+ p = pin;
+ if (!*p)
+ return NULL;
+ while (*pin && isdigit(*pin))
+ pin++;
+ if (*pin)
+ *pin = '\0';
+
+ return p;
+}
+
static int
mbim_pin_unlock_request(void)
{
(struct mbim_basic_connect_pin_s *) mbim_setup_command_msg(basic_connect,
MBIM_MESSAGE_COMMAND_TYPE_SET, MBIM_CMD_BASIC_CONNECT_PIN,
sizeof(struct mbim_basic_connect_pin_s));
+ char *pin = mbim_pin_sanitize(_argv[0]);
+
+ if (!pin || !strlen(pin)) {
+ fprintf(stderr, "failed to sanitize the pincode\n");
+ return -1;
+ }
p->pintype = htole32(MBIM_PIN_TYPE_PIN1);
p->pinoperation = htole32(MBIM_PIN_OPERATION_ENTER);
static int
usage(void)
{
- fprintf(stderr, "Usage: mbim <caps|pinstate|unlock|connect|disconnect> [options]\n"
+ fprintf(stderr, "Usage: umbim <caps|pinstate|unlock|registration|subscriber|attach|detach|connect|disconnect|config> [options]\n"
"Options:\n"
" -d <device> the device (/dev/cdc-wdmX)\n"
" -t <transaction> the transaction id\n"