+/*
+ * 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.
+ */
+
#include <sys/types.h>
#include <sys/stat.h>
snprintf(out, 16, "%d.%d.%d.%d", b[0], b[1], b[2], b[3]);
}
+void
+mbim_get_ipv6(void *buffer, char *out, uint32_t offset)
+{
+ uint8_t *b = buffer + offset;
+
+ snprintf(out, 40, "%x:%x:%x:%x:%x:%x:%x:%x", b[0] << 8 | b[1],
+ b[2] << 8 | b[3], b[4] << 8 | b[5], b[6] << 8 | b[7],
+ b[8] << 8 | b[9], b[10] << 8 | b[11], b[12] << 8 | b[13],
+ b[14] << 8 | b[15]);
+}
+
+uint32_t
+mbim_get_int(void *buffer, uint32_t offset)
+{
+ uint32_t *i = buffer + offset;
+
+ return le32toh(*i);
+}
+
const char*
mbim_enum_string(struct mbim_enum *e, uint32_t key)
{
{
struct command_message *cmd = (struct command_message *) mbim_buffer;
- memset(mbim_buffer, 0, MBIM_BUFFER_SIZE);
+ if (!mbim_buffer)
+ return NULL;
+ memset(mbim_buffer, 0, mbim_bufsize);
cmd->fragment_header.total = htole32(1);
cmd->fragment_header.current = htole32(0);
cmd->buffer_length = htole32(len);
payload_offset = len;
- payload_free = MBIM_BUFFER_SIZE - (sizeof(*cmd) + len);
+ payload_free = mbim_bufsize - (sizeof(*cmd) + len);
payload_len = 0;
payload_buffer = cmd->buffer;
{
struct command_message *cmd = (struct command_message *) mbim_buffer;
+ if (!mbim_buffer)
+ return 0;
if (payload_len & 0x3) {
payload_len &= ~0x3;
payload_len += 4;
struct mbim_open_message *msg = (struct mbim_open_message *) mbim_buffer;
mbim_setup_header(&msg->header, MBIM_MESSAGE_TYPE_OPEN, sizeof(*msg));
- msg->max_control_transfer = htole32(MBIM_BUFFER_SIZE);
+ msg->max_control_transfer = htole32(mbim_bufsize);
return mbim_send();
}
{
struct mbim_message_header *hdr = (struct mbim_message_header *) mbim_buffer;
- if (no_close) {
- uloop_end();
+ if (no_close || !mbim_buffer) {
+ mbim_end();
return 0;
}
mbim_setup_header(hdr, MBIM_MESSAGE_TYPE_CLOSE, sizeof(*hdr));