+/*
+ * umbim
+ * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#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;
memcpy(c->contexttype, uuid_context_type_internet, 16);
if (_argc > 0)
mbim_encode_string(&c->accessstring, *_argv);
-
+ 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);