aboutsummaryrefslogtreecommitdiff
path: root/libwmc/src
diff options
context:
space:
mode:
Diffstat (limited to 'libwmc/src')
-rw-r--r--libwmc/src/Makefile.am25
-rw-r--r--libwmc/src/com.c56
-rw-r--r--libwmc/src/com.h23
-rw-r--r--libwmc/src/commands.c466
-rw-r--r--libwmc/src/commands.h116
-rw-r--r--libwmc/src/errors.c58
-rw-r--r--libwmc/src/errors.h78
-rw-r--r--libwmc/src/protocol.h462
-rw-r--r--libwmc/src/result-private.h37
-rw-r--r--libwmc/src/result.c297
-rw-r--r--libwmc/src/result.h41
-rw-r--r--libwmc/src/utils.c459
-rw-r--r--libwmc/src/utils.h87
13 files changed, 0 insertions, 2205 deletions
diff --git a/libwmc/src/Makefile.am b/libwmc/src/Makefile.am
deleted file mode 100644
index b662f892..00000000
--- a/libwmc/src/Makefile.am
+++ /dev/null
@@ -1,25 +0,0 @@
-AM_CFLAGS = $(CODE_COVERAGE_CFLAGS)
-AM_LDFLAGS = $(CODE_COVERAGE_LDFLAGS)
-
-noinst_LTLIBRARIES = libwmc.la
-
-libwmc_la_CPPFLAGS = \
- $(MM_CFLAGS)
-
-libwmc_la_SOURCES = \
- protocol.h \
- result-private.h \
- errors.c \
- errors.h \
- utils.c \
- utils.h \
- result.c \
- result.h \
- com.c \
- com.h \
- commands.c \
- commands.h
-
-libwmc_la_LIBADD = \
- $(MM_LIBS)
-
diff --git a/libwmc/src/com.c b/libwmc/src/com.c
deleted file mode 100644
index f27d49a8..00000000
--- a/libwmc/src/com.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <errno.h>
-#include <termios.h>
-#include <fcntl.h>
-#include <string.h>
-
-#include "com.h"
-#include "errors.h"
-
-int
-wmc_port_setup (int fd)
-{
- struct termios stbuf;
-
- errno = 0;
- memset (&stbuf, 0, sizeof (stbuf));
- if (tcgetattr (fd, &stbuf) != 0) {
- wmc_err (0, "tcgetattr() error: %d", errno);
- return -WMC_ERROR_SERIAL_CONFIG_FAILED;
- }
-
- stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB);
- stbuf.c_iflag &= ~(HUPCL | IUTF8 | IUCLC | ISTRIP | IXON | IXOFF | IXANY | ICRNL);
- stbuf.c_oflag &= ~(OPOST | OCRNL | ONLCR | OLCUC | ONLRET);
- stbuf.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE | ECHOK | ECHONL);
- stbuf.c_lflag &= ~(NOFLSH | TOSTOP | ECHOPRT | ECHOCTL | ECHOKE);
- stbuf.c_cc[VMIN] = 1;
- stbuf.c_cc[VTIME] = 0;
- stbuf.c_cc[VEOF] = 1;
- stbuf.c_cflag |= (B115200 | CS8 | CREAD | 0 | 0); /* No parity, 1 stop bit */
-
- errno = 0;
- if (tcsetattr (fd, TCSANOW, &stbuf) < 0) {
- wmc_err (0, "tcgetattr() error: %d", errno);
- return -WMC_ERROR_SERIAL_CONFIG_FAILED;
- }
-
- return 0;
-}
-
diff --git a/libwmc/src/com.h b/libwmc/src/com.h
deleted file mode 100644
index 219a0169..00000000
--- a/libwmc/src/com.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBWMC_COM_H
-#define LIBWMC_COM_H
-
-int wmc_port_setup (int fd);
-
-#endif /* LIBWMC_COM_H */
diff --git a/libwmc/src/commands.c b/libwmc/src/commands.c
deleted file mode 100644
index 4c23460e..00000000
--- a/libwmc/src/commands.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <string.h>
-#include <time.h>
-
-#include "commands.h"
-#include "errors.h"
-#include "result-private.h"
-#include "utils.h"
-#include "protocol.h"
-
-
-/**********************************************************************/
-
-static int
-check_command (const char *buf, size_t len, uint8_t cmd, size_t min_len)
-{
- if (len < 1) {
- wmc_err (0, "Zero-length response");
- return -WMC_ERROR_RESPONSE_BAD_LENGTH;
- }
-
- if ((uint8_t) buf[0] != WMC_CMD_MARKER) {
- wmc_err (0, "Missing WMC command marker (expected 0x%02X, got 0x%02X)",
- WMC_CMD_MARKER, (uint8_t) buf[0]);
- return -WMC_ERROR_RESPONSE_UNEXPECTED;
- }
-
- if ((uint8_t) buf[1] != cmd) {
- wmc_err (0, "Unexpected WMC command response (expected 0x%02X, got 0x%02X)",
- (uint8_t) cmd, (uint8_t) buf[1]);
- return -WMC_ERROR_RESPONSE_UNEXPECTED;
- }
-
- if (len < min_len) {
- wmc_err (0, "WMC command %d response not long enough (got %zu, expected "
- "at least %zu).", cmd, len, min_len);
- return -WMC_ERROR_RESPONSE_BAD_LENGTH;
- }
-
- return 0;
-}
-
-/**********************************************************************/
-
-/**
- * wmc_cmd_init_new:
- * @buf: buffer in which to store constructed command
- * @buflen: size of @buf
- * @wmc2: if %TRUE add additional data that later-model devices (UML290) want
- *
- * Returns: size of the constructed command on success, or 0 on failure
- */
-size_t
-wmc_cmd_init_new (char *buf, size_t buflen, int wmc2)
-{
- wmc_return_val_if_fail (buf != NULL, 0);
-
- if (wmc2) {
- WmcCmdInit2 *cmd = (WmcCmdInit2 *) buf;
- time_t now;
- struct tm *tm;
-
- wmc_return_val_if_fail (buflen >= sizeof (*cmd), 0);
-
- now = time (NULL);
- tm = localtime (&now);
-
- memset (cmd, 0, sizeof (*cmd));
- cmd->hdr.marker = WMC_CMD_MARKER;
- cmd->hdr.cmd = WMC_CMD_INIT;
- cmd->year = htole16 (tm->tm_year + 1900);
- cmd->month = tm->tm_mon + 1;
- cmd->day = htobe16 (tm->tm_mday);
- cmd->hours = htobe16 (tm->tm_hour);
- cmd->minutes = htobe16 (tm->tm_min);
- cmd->seconds = htobe16 (tm->tm_sec);
- return sizeof (*cmd);
- } else {
- WmcCmdHeader *cmd = (WmcCmdHeader *) buf;
-
- wmc_return_val_if_fail (buflen >= sizeof (*cmd), 0);
-
- memset (cmd, 0, sizeof (*cmd));
- cmd->marker = WMC_CMD_MARKER;
- cmd->cmd = WMC_CMD_INIT;
- return sizeof (*cmd);
- }
-}
-
-WmcResult *
-wmc_cmd_init_result (const char *buf, size_t buflen, int wmc2)
-{
- wmc_return_val_if_fail (buf != NULL, NULL);
-
- if (wmc2) {
- if (check_command (buf, buflen, WMC_CMD_INIT, sizeof (WmcCmdInit2Rsp)) < 0)
- return NULL;
- } else {
- if (check_command (buf, buflen, WMC_CMD_INIT, sizeof (WmcCmdHeader)) < 0)
- return NULL;
- }
-
- return wmc_result_new ();
-}
-
-/**********************************************************************/
-
-size_t
-wmc_cmd_device_info_new (char *buf, size_t buflen)
-{
- WmcCmdHeader *cmd = (WmcCmdHeader *) buf;
-
- wmc_return_val_if_fail (buf != NULL, 0);
- wmc_return_val_if_fail (buflen >= sizeof (*cmd), 0);
-
- memset (cmd, 0, sizeof (*cmd));
- cmd->marker = WMC_CMD_MARKER;
- cmd->cmd = WMC_CMD_DEVICE_INFO;
- return sizeof (*cmd);
-}
-
-WmcResult *
-wmc_cmd_device_info_result (const char *buf, size_t buflen)
-{
- WmcResult *r = NULL;
- WmcCmdDeviceInfoRsp *rsp = (WmcCmdDeviceInfoRsp *) buf;
- WmcCmdDeviceInfo2Rsp *rsp2 = (WmcCmdDeviceInfo2Rsp *) buf;
- WmcCmdDeviceInfo3Rsp *rsp3 = (WmcCmdDeviceInfo3Rsp *) buf;
- char tmp[65];
-
- wmc_return_val_if_fail (buf != NULL, NULL);
-
- if (check_command (buf, buflen, WMC_CMD_DEVICE_INFO, sizeof (WmcCmdDeviceInfo3Rsp)) < 0) {
- rsp3 = NULL;
- if (check_command (buf, buflen, WMC_CMD_DEVICE_INFO, sizeof (WmcCmdDeviceInfo2Rsp)) < 0) {
- rsp2 = NULL;
- if (check_command (buf, buflen, WMC_CMD_DEVICE_INFO, sizeof (WmcCmdDeviceInfoRsp)) < 0)
- return NULL;
- }
- }
-
- r = wmc_result_new ();
-
- /* Manf */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp->manf) <= sizeof (tmp));
- memcpy (tmp, rsp->manf, sizeof (rsp->manf));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_MANUFACTURER, tmp);
-
- /* Model */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp->model) <= sizeof (tmp));
- memcpy (tmp, rsp->model, sizeof (rsp->model));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_MODEL, tmp);
-
- /* Firmware revision */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp->fwrev) <= sizeof (tmp));
- memcpy (tmp, rsp->fwrev, sizeof (rsp->fwrev));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_FW_REVISION, tmp);
-
- /* Hardware revision */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp->hwrev) <= sizeof (tmp));
- memcpy (tmp, rsp->hwrev, sizeof (rsp->hwrev));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_HW_REVISION, tmp);
-
- /* MIN */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp->min) <= sizeof (tmp));
- memcpy (tmp, rsp->min, sizeof (rsp->min));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_CDMA_MIN, tmp);
-
- wmc_result_add_u32 (r, WMC_CMD_DEVICE_INFO_ITEM_HOME_SID, le16toh (rsp->home_sid));
- wmc_result_add_u32 (r, WMC_CMD_DEVICE_INFO_ITEM_PRL_VERSION, le16toh (rsp->prlver));
- wmc_result_add_u32 (r, WMC_CMD_DEVICE_INFO_ITEM_ERI_VERSION, le16toh (rsp->eriver));
-
- if (rsp2) {
- /* MEID */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp2->meid) <= sizeof (tmp));
- memcpy (tmp, rsp2->meid, sizeof (rsp2->meid));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_MEID, tmp);
-
- /* IMEI */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp2->imei) <= sizeof (tmp));
- memcpy (tmp, rsp2->imei, sizeof (rsp2->imei));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_IMEI, tmp);
-
- /* IMSI */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp2->iccid) <= sizeof (tmp));
- memcpy (tmp, rsp2->iccid, sizeof (rsp2->iccid));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_ICCID, tmp);
- }
-
- if (rsp3) {
- /* MCC */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp3->mcc) <= sizeof (tmp));
- memcpy (tmp, rsp3->mcc, sizeof (rsp3->mcc));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_MCC, tmp);
-
- /* MNC */
- memset (tmp, 0, sizeof (tmp));
- wmc_assert (sizeof (rsp3->mnc) <= sizeof (tmp));
- memcpy (tmp, rsp3->mnc, sizeof (rsp3->mnc));
- wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_MNC, tmp);
- }
-
- return r;
-}
-
-/**********************************************************************/
-
-size_t
-wmc_cmd_network_info_new (char *buf, size_t buflen)
-{
- WmcCmdHeader *cmd = (WmcCmdHeader *) buf;
-
- wmc_return_val_if_fail (buf != NULL, 0);
- wmc_return_val_if_fail (buflen >= sizeof (*cmd), 0);
-
- memset (cmd, 0, sizeof (*cmd));
- cmd->marker = WMC_CMD_MARKER;
- cmd->cmd = WMC_CMD_NET_INFO;
- return sizeof (*cmd);
-}
-
-static wmcbool
-is_gsm_service (uint8_t service)
-{
- return (service == WMC_SERVICE_GSM || service == WMC_SERVICE_GPRS || service == WMC_SERVICE_EDGE);
-}
-
-static wmcbool
-is_umts_service (uint8_t service)
-{
- return (service == WMC_SERVICE_UMTS || service == WMC_SERVICE_HSDPA
- || service == WMC_SERVICE_HSUPA || service == WMC_SERVICE_HSPA);
-}
-
-static wmcbool
-is_cdma_service (uint8_t service)
-{
- return (service == WMC_SERVICE_IS95A || service == WMC_SERVICE_IS95B || service == WMC_SERVICE_1XRTT);
-}
-
-static wmcbool
-is_evdo_service (uint8_t service)
-{
- return (service == WMC_SERVICE_EVDO_0 || service == WMC_SERVICE_EVDO_A || service == WMC_SERVICE_EVDO_A_EHRPD);
-}
-
-static wmcbool
-is_lte_service (uint8_t service)
-{
- return (service == WMC_SERVICE_LTE);
-}
-
-static uint8_t
-sanitize_dbm (uint8_t in_dbm, uint8_t service)
-{
- uint8_t cutoff;
-
- /* 0x6A (-106 dBm) = no signal for GSM/GPRS/EDGE */
- /* 0x7D (-125 dBm) = no signal for everything else */
- cutoff = is_gsm_service (service) ? 0x6A : 0x7D;
-
- return in_dbm >= cutoff ? 0 : in_dbm;
-}
-
-
-WmcResult *
-wmc_cmd_network_info_result (const char *buf, size_t buflen)
-{
- WmcResult *r = NULL;
- WmcCmdNetworkInfoRsp *rsp = (WmcCmdNetworkInfoRsp *) buf;
- WmcCmdNetworkInfo2Rsp *rsp2 = (WmcCmdNetworkInfo2Rsp *) buf;
- WmcCmdNetworkInfo3Rsp *rsp3 = (WmcCmdNetworkInfo3Rsp *) buf;
- char tmp[65];
- int err;
- uint32_t mccmnc = 0, mcc, mnc;
-
- wmc_return_val_if_fail (buf != NULL, NULL);
-
- err = check_command (buf, buflen, WMC_CMD_NET_INFO, sizeof (WmcCmdNetworkInfo3Rsp));
- if (err != WMC_SUCCESS) {
- if (err != -WMC_ERROR_RESPONSE_BAD_LENGTH)
- return NULL;
- rsp3 = NULL;
-
- err = check_command (buf, buflen, WMC_CMD_NET_INFO, sizeof (WmcCmdNetworkInfo2Rsp));
- if (err != WMC_SUCCESS) {
- if (err != -WMC_ERROR_RESPONSE_BAD_LENGTH)
- return NULL;
- rsp2 = NULL;
-
- err = check_command (buf, buflen, WMC_CMD_NET_INFO, sizeof (WmcCmdNetworkInfoRsp));
- if (err != WMC_SUCCESS)
- return NULL;
- }
- }
-
- r = wmc_result_new ();
-
- wmc_result_add_u8 (r, WMC_CMD_NETWORK_INFO_ITEM_SERVICE, rsp->service);
-
- if (rsp2) {
- wmc_result_add_u8 (r, WMC_CMD_NETWORK_INFO_ITEM_2G_DBM, sanitize_dbm (rsp2->two_g_dbm, rsp->service));
- wmc_result_add_u8 (r, WMC_CMD_NETWORK_INFO_ITEM_3G_DBM, sanitize_dbm (rsp2->three_g_dbm, WMC_SERVICE_NONE));
-
- memset (tmp, 0, sizeof (tmp));
- if ( (is_cdma_service (rsp->service) && sanitize_dbm (rsp2->two_g_dbm, rsp->service))
- || (is_evdo_service (rsp->service) && sanitize_dbm (rsp2->three_g_dbm, rsp->service))) {
- /* CDMA2000 operator name */
- wmc_assert (sizeof (rsp2->cdma_opname) <= sizeof (tmp));
- memcpy (tmp, rsp2->cdma_opname, sizeof (rsp2->cdma_opname));
- wmc_result_add_string (r, WMC_CMD_NETWORK_INFO_ITEM_OPNAME, tmp);
- } else {
- if ( (is_gsm_service (rsp->service) && sanitize_dbm (rsp2->two_g_dbm, rsp->service))
- || (is_umts_service (rsp->service) && sanitize_dbm (rsp2->three_g_dbm, rsp->service))) {
- /* GSM/UMTS operator name */
- wmc_assert (sizeof (rsp2->tgpp_opname) <= sizeof (tmp));
- memcpy (tmp, rsp2->tgpp_opname, sizeof (rsp2->tgpp_opname));
- wmc_result_add_string (r, WMC_CMD_NETWORK_INFO_ITEM_OPNAME, tmp);
- }
- }
-
- /* MCC/MNC */
- mccmnc = le32toh (rsp2->mcc_mnc);
- if (mccmnc < 100000)
- mccmnc *= 10; /* account for possible 2-digit MNC */
- mcc = mccmnc / 1000;
- mnc = mccmnc - (mcc * 1000);
-
- if (mcc > 100) {
- memset (tmp, 0, sizeof (tmp));
- snprintf (tmp, sizeof (tmp), "%u", mccmnc / 1000);
- wmc_result_add_string (r, WMC_CMD_NETWORK_INFO_ITEM_MCC, tmp);
-
- memset (tmp, 0, sizeof (tmp));
- snprintf (tmp, sizeof (tmp), "%03u", mnc);
- wmc_result_add_string (r, WMC_CMD_NETWORK_INFO_ITEM_MNC, tmp);
- }
- } else {
- /* old format */
- wmc_result_add_u8 (r, WMC_CMD_NETWORK_INFO_ITEM_2G_DBM, sanitize_dbm (rsp->two_g_dbm, rsp->service));
- }
-
- if (rsp3) {
- wmc_result_add_u8 (r, WMC_CMD_NETWORK_INFO_ITEM_LTE_DBM, sanitize_dbm (rsp3->lte_dbm, WMC_SERVICE_NONE));
-
- memset (tmp, 0, sizeof (tmp));
- if (is_lte_service (rsp->service) && sanitize_dbm (rsp3->lte_dbm, rsp->service)) {
- /* LTE operator name */
- wmc_assert (sizeof (rsp2->tgpp_opname) <= sizeof (tmp));
- memcpy (tmp, rsp2->tgpp_opname, sizeof (rsp2->tgpp_opname));
- wmc_result_add_string (r, WMC_CMD_NETWORK_INFO_ITEM_OPNAME, tmp);
- }
- }
-
- return r;
-}
-
-/**********************************************************************/
-
-size_t
-wmc_cmd_get_global_mode_new (char *buf, size_t buflen)
-{
- WmcCmdGetGlobalMode *cmd = (WmcCmdGetGlobalMode *) buf;
-
- wmc_return_val_if_fail (buf != NULL, 0);
- wmc_return_val_if_fail (buflen >= sizeof (*cmd), 0);
-
- memset (cmd, 0, sizeof (*cmd));
- cmd->hdr.marker = WMC_CMD_MARKER;
- cmd->hdr.cmd = WMC_CMD_GET_GLOBAL_MODE;
- return sizeof (*cmd);
-}
-
-WmcResult *
-wmc_cmd_get_global_mode_result (const char *buf, size_t buflen)
-{
- WmcResult *r = NULL;
- WmcCmdGetGlobalModeRsp *rsp = (WmcCmdGetGlobalModeRsp *) buf;
-
- wmc_return_val_if_fail (buf != NULL, NULL);
-
- if (check_command (buf, buflen, WMC_CMD_GET_GLOBAL_MODE, sizeof (WmcCmdGetGlobalModeRsp)) < 0)
- return NULL;
-
- r = wmc_result_new ();
- wmc_result_add_u8 (r, WMC_CMD_GET_GLOBAL_MODE_ITEM_MODE, rsp->mode);
- return r;
-}
-
-/**********************************************************************/
-
-static wmcbool
-validate_mode (uint8_t mode)
-{
- switch (mode) {
- case WMC_NETWORK_MODE_AUTO_CDMA:
- case WMC_NETWORK_MODE_CDMA_ONLY:
- case WMC_NETWORK_MODE_EVDO_ONLY:
- case WMC_NETWORK_MODE_AUTO_GSM:
- case WMC_NETWORK_MODE_GPRS_ONLY:
- case WMC_NETWORK_MODE_UMTS_ONLY:
- case WMC_NETWORK_MODE_AUTO:
- case WMC_NETWORK_MODE_LTE_ONLY:
- return TRUE;
- default:
- break;
- }
- return FALSE;
-}
-
-size_t
-wmc_cmd_set_global_mode_new (char *buf, size_t buflen, uint8_t mode)
-{
- WmcCmdSetGlobalMode *cmd = (WmcCmdSetGlobalMode *) buf;
-
- wmc_return_val_if_fail (buf != NULL, 0);
- wmc_return_val_if_fail (buflen >= sizeof (*cmd), 0);
- wmc_return_val_if_fail (validate_mode (mode) == TRUE, 0);
-
- memset (cmd, 0, sizeof (*cmd));
- cmd->hdr.marker = WMC_CMD_MARKER;
- cmd->hdr.cmd = WMC_CMD_SET_GLOBAL_MODE;
- cmd->_unknown1 = 0x01;
- cmd->mode = mode;
- cmd->_unknown2 = 0x05;
- cmd->_unknown3 = 0x00;
- return sizeof (*cmd);
-}
-
-WmcResult *
-wmc_cmd_set_global_mode_result (const char *buf, size_t buflen)
-{
- wmc_return_val_if_fail (buf != NULL, NULL);
-
- if (check_command (buf, buflen, WMC_CMD_SET_GLOBAL_MODE, sizeof (WmcCmdGetGlobalModeRsp)) < 0)
- return NULL;
-
- return wmc_result_new ();
-}
-
-/**********************************************************************/
diff --git a/libwmc/src/commands.h b/libwmc/src/commands.h
deleted file mode 100644
index 75c1afd4..00000000
--- a/libwmc/src/commands.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBWMC_COMMANDS_H
-#define LIBWMC_COMMANDS_H
-
-#include "result.h"
-
-/**********************************************************************/
-
-/* Generic enums */
-
-/**********************************************************************/
-
-size_t wmc_cmd_init_new (char *buf, size_t buflen, int wmc2);
-
-WmcResult * wmc_cmd_init_result (const char *buf, size_t len, int wmc2);
-
-/**********************************************************************/
-
-#define WMC_CMD_DEVICE_INFO_ITEM_MANUFACTURER "manufacturer"
-#define WMC_CMD_DEVICE_INFO_ITEM_MODEL "model"
-#define WMC_CMD_DEVICE_INFO_ITEM_FW_REVISION "firmware-revision"
-#define WMC_CMD_DEVICE_INFO_ITEM_HW_REVISION "hardware-revision"
-#define WMC_CMD_DEVICE_INFO_ITEM_CDMA_MIN "cdma-min"
-#define WMC_CMD_DEVICE_INFO_ITEM_HOME_SID "home-sid"
-#define WMC_CMD_DEVICE_INFO_ITEM_PRL_VERSION "prl-version"
-#define WMC_CMD_DEVICE_INFO_ITEM_ERI_VERSION "eri-version"
-#define WMC_CMD_DEVICE_INFO_ITEM_MEID "meid"
-#define WMC_CMD_DEVICE_INFO_ITEM_IMEI "imei"
-#define WMC_CMD_DEVICE_INFO_ITEM_ICCID "iccid"
-#define WMC_CMD_DEVICE_INFO_ITEM_MCC "mcc"
-#define WMC_CMD_DEVICE_INFO_ITEM_MNC "mnc"
-
-size_t wmc_cmd_device_info_new (char *buf, size_t buflen);
-
-WmcResult * wmc_cmd_device_info_result (const char *buf, size_t len);
-
-/**********************************************************************/
-
-enum {
- WMC_NETWORK_SERVICE_NONE = 0,
- WMC_NETWORK_SERVICE_AMPS = 1,
- WMC_NETWORK_SERVICE_IS95A = 2,
- WMC_NETWORK_SERVICE_IS95B = 3,
- WMC_NETWORK_SERVICE_GSM = 4,
- WMC_NETWORK_SERVICE_GPRS = 5,
- WMC_NETWORK_SERVICE_1XRTT = 6,
- WMC_NETWORK_SERVICE_EVDO_0 = 7,
- WMC_NETWORK_SERVICE_UMTS = 8,
- WMC_NETWORK_SERVICE_EVDO_A = 9,
- WMC_NETWORK_SERVICE_EDGE = 10,
- WMC_NETWORK_SERVICE_HSDPA = 11,
- WMC_NETWORK_SERVICE_HSUPA = 12,
- WMC_NETWORK_SERVICE_HSPA = 13,
- WMC_NETWORK_SERVICE_LTE = 14,
- WMC_NETWORK_SERVICE_EVDO_A_EHRPD = 15
-};
-
-/* One of WMC_NETWORK_SERVICE_* */
-#define WMC_CMD_NETWORK_INFO_ITEM_SERVICE "service"
-
-#define WMC_CMD_NETWORK_INFO_ITEM_2G_DBM "2g-dbm"
-#define WMC_CMD_NETWORK_INFO_ITEM_3G_DBM "3g-dbm"
-#define WMC_CMD_NETWORK_INFO_ITEM_LTE_DBM "lte-dbm"
-#define WMC_CMD_NETWORK_INFO_ITEM_OPNAME "opname"
-#define WMC_CMD_NETWORK_INFO_ITEM_MCC "mcc"
-#define WMC_CMD_NETWORK_INFO_ITEM_MNC "mnc"
-
-size_t wmc_cmd_network_info_new (char *buf, size_t buflen);
-
-WmcResult * wmc_cmd_network_info_result (const char *buf, size_t len);
-
-/**********************************************************************/
-
-enum {
- WMC_NETWORK_MODE_AUTO_CDMA = 0x00,
- WMC_NETWORK_MODE_CDMA_ONLY = 0x01,
- WMC_NETWORK_MODE_EVDO_ONLY = 0x02,
- WMC_NETWORK_MODE_AUTO_GSM = 0x0A,
- WMC_NETWORK_MODE_GPRS_ONLY = 0x0B,
- WMC_NETWORK_MODE_UMTS_ONLY = 0x0C,
- WMC_NETWORK_MODE_AUTO = 0x14,
- WMC_NETWORK_MODE_LTE_ONLY = 0x1E,
-};
-
-/* One of WMC_NETWORK_MODE_* */
-#define WMC_CMD_GET_GLOBAL_MODE_ITEM_MODE "mode"
-
-size_t wmc_cmd_get_global_mode_new (char *buf, size_t buflen);
-
-WmcResult * wmc_cmd_get_global_mode_result (const char *buf, size_t len);
-
-/**********************************************************************/
-
-size_t wmc_cmd_set_global_mode_new (char *buf, size_t buflen, uint8_t mode);
-
-WmcResult * wmc_cmd_set_global_mode_result (const char *buf, size_t len);
-
-/**********************************************************************/
-
-#endif /* LIBWMC_COMMANDS_H */
diff --git a/libwmc/src/errors.c b/libwmc/src/errors.c
deleted file mode 100644
index 0403b229..00000000
--- a/libwmc/src/errors.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "errors.h"
-#include <stdlib.h>
-#include <string.h>
-
-void
-_wmc_log (const char *file,
- int line,
- const char *func,
- int level,
- int domain,
- const char *format,
- ...)
-{
- va_list args;
- char *message = NULL;
- int n;
- const char *prefix = "info";
-
- wmc_return_if_fail (format != NULL);
- wmc_return_if_fail (format[0] != '\0');
-
- /* level & domain ignored for now */
-
- if (getenv ("WMC_DEBUG") == NULL)
- return;
-
- va_start (args, format);
- n = vasprintf (&message, format, args);
- va_end (args);
-
- if (level & LOGL_ERR)
- prefix = "err";
- else if (level & LOGL_DEBUG)
- prefix = "dbg";
-
- if (n >= 0) {
- fprintf (stderr, "<%s> [%s:%u] %s(): %s\n", prefix, file, line, func, message);
- free (message);
- }
-}
-
diff --git a/libwmc/src/errors.h b/libwmc/src/errors.h
deleted file mode 100644
index 18a99794..00000000
--- a/libwmc/src/errors.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBWMC_ERRORS_H
-#define LIBWMC_ERRORS_H
-
-#include <config.h>
-#include <sys/types.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-enum {
- LOGL_ERR = 0x00000001,
- LOGL_WARN = 0x00000002,
- LOGL_INFO = 0x00000004,
- LOGL_DEBUG = 0x00000008
-};
-
-enum {
- WMC_SUCCESS = 0,
- WMC_ERROR_INVALID_ARGUMENTS = 1,
- WMC_ERROR_SERIAL_CONFIG_FAILED = 2,
- WMC_ERROR_VALUE_NOT_FOUND = 3,
- WMC_ERROR_RESPONSE_UNEXPECTED = 4,
- WMC_ERROR_RESPONSE_BAD_LENGTH = 5,
-};
-
-#define wmc_assert assert
-
-#define wmc_return_if_fail(e) \
-{ \
- if (!(e)) { \
- wmc_warn (0, "failed: " #e "\n"); \
- return; \
- } \
-}
-
-#define wmc_return_val_if_fail(e, v) \
-{ \
- if (!(e)) { \
- wmc_warn (0, "failed: " #e "\n"); \
- return v; \
- } \
-}
-
-void _wmc_log (const char *file,
- int line,
- const char *func,
- int domain,
- int level,
- const char *format,
- ...) __attribute__((__format__ (__printf__, 6, 7)));
-
-#define wmc_dbg(domain, ...) \
- _wmc_log (__FILE__, __LINE__, __func__, domain, LOGL_DEBUG, ## __VA_ARGS__ )
-
-#define wmc_warn(domain, ...) \
- _wmc_log (__FILE__, __LINE__, __func__, domain, LOGL_WARN, ## __VA_ARGS__ )
-
-#define wmc_err(domain, ...) \
- _wmc_log (__FILE__, __LINE__, __func__, domain, LOGL_ERR, ## __VA_ARGS__ )
-
-#endif /* LIBWMC_ERRORS_H */
diff --git a/libwmc/src/protocol.h b/libwmc/src/protocol.h
deleted file mode 100644
index 483edbcd..00000000
--- a/libwmc/src/protocol.h
+++ /dev/null
@@ -1,462 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBWMC_PROTOCOL_H
-#define LIBWMC_PROTOCOL_H
-
-#define WMC_CMD_MARKER ((uint8_t) 0xC8)
-
-enum {
- WMC_CMD_GET_GLOBAL_MODE = 0x03,
- WMC_CMD_SET_GLOBAL_MODE = 0x04,
- WMC_CMD_DEVICE_INFO = 0x06,
- WMC_CMD_CONNECTION_INFO = 0x0A,
- WMC_CMD_NET_INFO = 0x0B,
- WMC_CMD_INIT = 0x0D,
- WMC_CMD_FIELD_TEST = 0x0F,
- WMC_CMD_SET_OPERATOR = 0x33,
- WMC_CMD_GET_FIRST_OPERATOR = 0x34,
- WMC_CMD_GET_NEXT_OPERATOR = 0x35,
- WMC_CMD_GET_APN = 0x4D,
-};
-
-/* MCC/MNC representation
- *
- * Various commands accept or return an MCC/MNC. When sending, convert
- * the MCC/MNC into a number using eg. atoi() and store it as an LE 32-bit
- * value. 3-digit MNCs appear to be sent as 3-digit only if the firmware
- * reports them as 3-digit. For example:
- *
- * T-Mobile US: 310-260
- * mcc_mnc = 0x00007932 = 31026 (note the 2-digit-only MNC)
- *
- * AT&T: 310-410
- * mcc_mnc = 0x0004bc8a = 310410
- */
-
-
-/* Generic WMC command header */
-struct WmcCmdHeader {
- uint8_t marker; /* Always 0xC8 */
- uint8_t cmd;
-} __attribute__ ((packed));
-typedef struct WmcCmdHeader WmcCmdHeader;
-
-/* Used on newer devices like the UML190 and later */
-struct WmcCmdInit2 {
- WmcCmdHeader hdr;
- uint16_t year;
- uint8_t month;
- uint16_t day; /* big endian */
- uint16_t hours; /* big endian */
- uint16_t minutes; /* big endian */
- uint16_t seconds; /* big endian */
- uint8_t _unknown1[3];
-} __attribute__ ((packed));
-typedef struct WmcCmdInit2 WmcCmdInit2;
-
-struct WmcCmdInit2Rsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1[4];
-} __attribute__ ((packed));
-typedef struct WmcCmdInit2Rsp WmcCmdInit2Rsp;
-
-struct WmcCmdDeviceInfoRsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1[27];
- char manf[64];
- char model[64];
- char fwrev[64];
- char hwrev[64];
- uint8_t _unknown2[64];
- uint8_t _unknown3[64];
- char min[10]; /* CDMA2000/IS-95 MIN */
- uint8_t _unknown4[12];
- uint16_t home_sid;
- uint8_t _unknown5[2];
- uint16_t prlver;
- uint8_t _unknown6[2];
- uint16_t eriver;
- uint8_t _unknown7[4];
-} __attribute__ ((packed));
-typedef struct WmcCmdDeviceInfoRsp WmcCmdDeviceInfoRsp;
-
-struct WmcCmdDeviceInfo2Rsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1[27];
- char manf[64];
- char model[64];
- char fwrev[64];
- char hwrev[64];
- uint8_t _unknown2[64];
- uint8_t _unknown3[64];
- uint8_t min[10]; /* CDMA2000/IS-95 MIN */
- uint8_t _unknown4[12];
- uint16_t home_sid;
- uint8_t _unknown5[2];
- uint16_t prlver;
- uint8_t _unknown6[2];
- uint16_t eriver;
- uint8_t _unknown7[4];
- uint8_t _unknown8[64];
- uint8_t meid[14];
- uint8_t _unknown10[6]; /* always zero */
- uint8_t imei[16];
- uint8_t _unknown11[6]; /* always zero */
- uint8_t _unknown12[16];
- uint8_t iccid[20];
- uint8_t _unknown13[6];
-} __attribute__ ((packed));
-typedef struct WmcCmdDeviceInfo2Rsp WmcCmdDeviceInfo2Rsp;
-
-struct WmcCmdDeviceInfo3Rsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1[27];
- char manf[64];
- char model[64];
- char fwrev[64];
- char hwrev[64];
- uint8_t _unknown2[64];
- uint8_t _unknown3[64];
- uint8_t min[10]; /* CDMA2000/IS-95 MIN */
- uint8_t _unknown4[12];
- uint16_t home_sid;
- uint8_t _unknown5[2];
- uint16_t prlver;
- uint8_t _unknown6[2];
- uint16_t eri_ver;
- uint8_t _unknown7[4];
- uint8_t _unknown8[64];
- uint8_t meid[14];
- uint8_t _unknown10[6]; /* always zero */
- uint8_t imei[16];
- uint8_t _unknown11[6]; /* always zero */
- uint8_t _unknown12[16];
- uint8_t iccid[20];
- uint8_t _unknown13[6];
- uint8_t mcc[16];
- uint8_t mnc[16];
- uint8_t _unknown14[4];
- uint8_t _unknown15[4];
- uint8_t _unknown16[4];
-} __attribute__ ((packed));
-typedef struct WmcCmdDeviceInfo3Rsp WmcCmdDeviceInfo3Rsp;
-
-/*****************************************************/
-
-enum {
- WMC_SERVICE_NONE = 0,
- WMC_SERVICE_AMPS = 1,
- WMC_SERVICE_IS95A = 2,
- WMC_SERVICE_IS95B = 3,
- WMC_SERVICE_GSM = 4,
- WMC_SERVICE_GPRS = 5,
- WMC_SERVICE_1XRTT = 6,
- WMC_SERVICE_EVDO_0 = 7,
- WMC_SERVICE_UMTS = 8,
- WMC_SERVICE_EVDO_A = 9,
- WMC_SERVICE_EDGE = 10,
- WMC_SERVICE_HSDPA = 11,
- WMC_SERVICE_HSUPA = 12,
- WMC_SERVICE_HSPA = 13,
- WMC_SERVICE_LTE = 14,
- WMC_SERVICE_EVDO_A_EHRPD = 15,
-};
-
-/* PC5740 response */
-struct WmcCmdNetworkInfoRsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1;
- uint8_t _unknown2[3]; /* Always zero */
- uint8_t service; /* One of WMC_SERVICE_* */
- uint8_t _unknown3; /* Either 0x00 or 0x01 */
- uint16_t ts_year;
- uint8_t ts_month;
- uint16_t ts_day; /* BE */
- uint16_t ts_hours; /* BE */
- uint16_t ts_minutes; /* BE */
- uint16_t ts_seconds; /* BE */
- uint16_t counter1; /* A timestamp/counter? */
- uint16_t _unknown4;
- uint8_t _unknown5[3]; /* Always 0xFE 0xFF 0xFF */
- uint8_t two_g_dbm; /* 0x7D = no signal */
- uint8_t _unknown6[37]; /* Always zero */
-} __attribute__ ((packed));
-typedef struct WmcCmdNetworkInfoRsp WmcCmdNetworkInfoRsp;
-
-/* UML190 response */
-struct WmcCmdNetworkInfo2Rsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1; /* 0x00 on LTE, 0x07 or 0x1F on CDMA */
- uint8_t _unknown2[3]; /* Always zero */
- uint8_t service; /* One of WMC_SERVICE_* */
- uint8_t _unknown3;
- uint16_t ts_year;
- uint8_t ts_month;
- uint16_t ts_day; /* BE */
- uint16_t ts_hours; /* BE */
- uint16_t ts_minutes; /* BE */
- uint16_t ts_seconds; /* BE */
- uint8_t _unknown4; /* always zero */
- uint16_t uptime_secs;
- uint8_t _unknown5;
- uint8_t _unknown6[3]; /* always zero on LTE, 0xFE 0xFF 0xFF on CDMA */
- uint8_t two_g_dbm; /* 0x7D = no CDMA signal, 0x6a = no GSM signal */
- uint8_t _unknown7[3]; /* Always zero */
- uint8_t cdma_opname[16]; /* Zero terminated? */
- uint8_t _unknown8[18]; /* Always zero */
- uint8_t three_g_dbm; /* 0x7D = no signal */
- uint8_t _unknown9[3]; /* Always zero */
- uint8_t _unknown10; /* 0x01 on LTE, 0x40 on CDMA */
- uint8_t _unknown11[3]; /* Always zero */
- uint8_t _unknown12; /* Always 0x01 */
- uint8_t tgpp_opname[8]; /* 3GPP operator name (Zero terminated? Sometimes "MCC MNC" too */
- uint8_t _unknown13[4]; /* Always zero */
- uint32_t _unknown14; /* 43 75 3a 00 on GSM/WCDMA mode, zero on others */
- uint32_t _unknown15; /* 49 7d 3a 00 on GSM/WCDMA mode, zero on others */
- uint8_t _unknown16[44]; /* Always zero */
- uint32_t mcc_mnc; /* GSM/WCDMA only, see MCC/MNC format note */
-} __attribute__ ((packed));
-typedef struct WmcCmdNetworkInfo2Rsp WmcCmdNetworkInfo2Rsp;
-
-/* UML290 response */
-struct WmcCmdNetworkInfo3Rsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1; /* 0x00 on LTE, 0x07 or 0x1F on CDMA */
- uint8_t _unknown2[3]; /* Always zero */
- uint8_t service; /* One of WMC_SERVICE_* */
- uint8_t _unknown3;
- uint16_t ts_year;
- uint8_t ts_month;
- uint16_t ts_day; /* BE */
- uint16_t ts_hours; /* BE */
- uint16_t ts_minutes; /* BE */
- uint16_t ts_seconds; /* BE */
- uint8_t _unknown4; /* always zero */
- uint16_t uptime_secs;
- uint8_t _unknown5;
- uint8_t _unknown6[3]; /* always zero on LTE, 0xFE 0xFF 0xFF on CDMA */
- uint8_t two_g_dbm; /* 0x7D = no CDMA signal, 0x6a = no GSM signal */
- uint8_t _unknown7[3]; /* Always zero */
- uint8_t cdma_opname[16]; /* Zero terminated? */
- uint8_t _unknown8[18]; /* Always zero */
- uint8_t three_g_dbm; /* 0x7D = no signal */
- uint8_t _unknown9[3]; /* Always zero */
- uint8_t _unknown10; /* 0x01 on LTE, 0x40 on CDMA */
- uint8_t _unknown11[3]; /* Always zero */
- uint8_t _unknown12; /* Always 0x01 */
- uint8_t tgpp_opname[8]; /* Zero terminated? Sometimes "MCC MNC" too */
- uint8_t _unknown13[4]; /* Always zero */
- uint32_t _unknown14; /* 43 75 3a 00 on GSM/WCDMA mode, zero on others */
- uint32_t _unknown15; /* 49 7d 3a 00 on GSM/WCDMA mode, zero on others */
- uint8_t _unknown16[44]; /* Always zero */
- uint32_t mcc_mnc; /* GSM/WCDMA only, see MCC/MNC format note */
- uint8_t lte_dbm; /* 0x00 if not in LTE mode */
- uint8_t _unknown17[3]; /* Always zero */
- uint8_t _unknown18[4];
-} __attribute__ ((packed));
-typedef struct WmcCmdNetworkInfo3Rsp WmcCmdNetworkInfo3Rsp;
-
-/*****************************************************/
-
-enum {
- WMC_CONNECTION_STATE_UNKNOWN = 0,
- WMC_CONNECTION_STATE_IDLE = 1,
- WMC_CONNECTION_STATE_CONNECTING = 2,
- WMC_CONNECTION_STATE_AUTHENTICATING = 3,
- WMC_CONNECTION_STATE_CONNECTED = 4,
- WMC_CONNECTION_STATE_DORMANT = 5,
- WMC_CONNECTION_STATE_UPDATING_NAM = 6,
- WMC_CONNECTION_STATE_UPDATING_PRL = 7,
- WMC_CONNECTION_STATE_DISCONNECTING = 8,
- WMC_CONNECTION_STATE_ERROR = 9,
- WMC_CONNECTION_STATE_UPDATING_UICC = 10,
- WMC_CONNECTION_STATE_UPDATING_PLMN = 11
-};
-
-/* Used on UML190 */
-struct WmcCmdConnectionInfoRsp {
- WmcCmdHeader hdr;
- uint32_t rx_bytes;
- uint32_t tx_bytes;
- uint8_t _unknown1[8];
- uint8_t state; /* One of WMC_CONNECTION_STATE_* */
- uint8_t _unknown2[3]; /* Always 0xc0 0x0b 0x00 */
-} __attribute__ ((packed));
-typedef struct WmcCmdConnectionInfoRsp WmcCmdConnectionInfoRsp;
-
-/* Used on UML290 */
-struct WmcCmdConnectionInfo2Rsp {
- WmcCmdHeader hdr;
- uint32_t rx_bytes;
- uint32_t tx_bytes;
- uint8_t _unknown1[8];
- uint8_t state; /* One of WMC_CONNECTION_STATE_* */
- uint8_t _unknown2[3]; /* Always 0xc0 0x0b 0x00 */
- uint8_t _unknown3[4]; /* Always 0x01 0x00 0x00 0x00 */
- uint8_t ip4_address[16]; /* String format, ie "10.156.45.3" */
- uint8_t _unknown4[8]; /* Netmask? */
- uint8_t ip6_address[40]; /* String format */
-} __attribute__ ((packed));
-typedef struct WmcCmdConnection2InfoRsp WmcCmdConnection2InfoRsp;
-
-/*****************************************************/
-
-enum {
- WMC_GLOBAL_MODE_AUTO_CDMA = 0x00,
- WMC_GLOBAL_MODE_CDMA_ONLY = 0x01,
- WMC_GLOBAL_MODE_EVDO_ONLY = 0x02,
- WMC_GLOBAL_MODE_AUTO_GSM = 0x0A,
- WMC_GLOBAL_MODE_GPRS_ONLY = 0x0B,
- WMC_GLOBAL_MODE_UMTS_ONLY = 0x0C,
- WMC_GLOBAL_MODE_AUTO = 0x14,
- WMC_GLOBAL_MODE_LTE_ONLY = 0x1E,
-};
-
-struct WmcCmdGetGlobalMode {
- WmcCmdHeader hdr;
- uint8_t _unknown1; /* always 0 */
-} __attribute__ ((packed));
-typedef struct WmcCmdGetGlobalMode WmcCmdGetGlobalMode;
-
-struct WmcCmdGetGlobalModeRsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1; /* always 0x01 */
- uint8_t mode; /* one of WMC_GLOBAL_MODE_* */
- uint8_t _unknown2; /* always 0x05 */
- uint8_t _unknown3; /* always 0x00 */
-} __attribute__ ((packed));
-typedef struct WmcCmdGetGlobalModeRsp WmcCmdGetGlobalModeRsp;
-
-/*****************************************************/
-
-struct WmcCmdSetGlobalMode {
- WmcCmdHeader hdr;
- uint8_t _unknown1; /* always 0x01 */
- uint8_t mode; /* one of WMC_GLOBAL_MODE_* */
- uint8_t _unknown2; /* always 0x05 */
- uint8_t _unknown3; /* always 0x00 */
-} __attribute__ ((packed));
-typedef struct WmcCmdSetGlobalMode WmcCmdSetGlobalMode;
-
-struct WmcCmdSetGlobalModeRsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1; /* always 0x01 */
- uint32_t _unknown2; /* always zero */
-} __attribute__ ((packed));
-typedef struct WmcCmdSetGlobalModeRsp WmcCmdSetGlobalModeRsp;
-
-/*****************************************************/
-
-struct WmcCmdSetOperator {
- WmcCmdHeader hdr;
- uint8_t automatic; /* 0x00 = manual, 0x01 = auto */
- uint8_t _unknown1; /* always 0x50 */
- uint8_t _unknown2[3]; /* always zero */
- uint32_t mcc_mnc; /* MCC/MNC for manual reg (see format note), zero for auto */
- uint8_t _unknown3[56]; /* always zero */
-} __attribute__ ((packed));
-typedef struct WmcCmdSetOperator WmcCmdSetOperator;
-
-enum {
- WMC_SET_OPERATOR_STATUS_OK = 0,
- WMC_SET_OPERATOR_STATUS_REGISTERING = 0x63,
- WMC_SET_OPERATOR_STATUS_FAILED = 0x68,
-};
-
-struct WmcCmdSetOperatorRsp {
- WmcCmdHeader hdr;
- uint8_t status; /* one of WMC_SET_OPERATOR_STATUS_* */
- uint8_t _unknown1[3]; /* always zero */
-} __attribute__ ((packed));
-typedef struct WmcCmdSetOperatorRsp WmcCmdSetOperatorRsp;
-
-/*****************************************************/
-
-enum {
- WMC_OPERATOR_SERVICE_UNKNOWN = 0,
- WMC_OPERATOR_SERVICE_GSM = 1,
- WMC_OPERATOR_SERVICE_UMTS = 2,
-};
-
-/* Response for both GET_FIRST_OPERATOR and GET_NEXT_OPERATOR */
-struct WmcCmdGetOperatorRsp {
- WmcCmdHeader hdr;
- uint8_t _unknown1; /* Usually 0x50, sometimes 0x00 */
- uint8_t _unknown2[3]; /* always zero */
- uint32_t mcc_mnc; /* see format note */
- uint8_t opname[8];
- uint8_t _unknown3[56]; /* always zero */
- uint8_t stat; /* follows 3GPP TS27.007 +COPS <stat> ? */
- uint8_t _unknown4[3]; /* always zero */
- uint8_t service; /* one of WMC_OPERATOR_SERVICE_* */
- uint8_t _unknown5[3]; /* always zero */
- uint8_t _unknown6; /* 0x63 (GET_FIRST_OP) might mean "wait" */
- uint8_t _unknown7; /* 0x00 or 0x01 */
- uint8_t _unknown8[2]; /* always zero */
-} __attribute__ ((packed));
-typedef struct WmcCmdGetOperatorRsp WmcCmdGetOperatorRsp;
-
-/*****************************************************/
-
-enum {
- WMC_FIELD_TEST_MOBILE_IP_MODE_MIP_OFF = 0,
- WMC_FIELD_TEST_MOBILE_IP_MODE_MIP_PREF = 1,
- WMC_FIELD_TEST_MOBILE_IP_MODE_MIP_ONLY = 2
-};
-
-/* Later devices return all zeros for this command */
-struct WmcCmdFieldTestRsp {
- WmcCmdHeader hdr;
- uint8_t prl_requirements;
- uint8_t eri_support;
- char nam_name[7];
- uint8_t _unknown1; /* always zero */
- uint8_t _unknown2[3]; /* always 0x0A 0x0A 0x0A */
- uint8_t _unknown3[5]; /* always zero */
- uint8_t _unknown4[10]; /* all 0x0F */
- uint16_t home_sid;
- uint16_t home_nid;
- char min1[7];
- char min2[3];
- char mcc[3];
- char imsi_s[10];
- char mnc[2];
- uint16_t primary_cdma_chan_a;
- uint16_t secondary_cdma_chan_a;
- uint16_t primary_cdma_chan_b;
- uint16_t secondary_cdma_chan_b;
- uint8_t accolc;
- char sw_version[64];
- char hw_version[64];
- uint16_t prlver;
- uint16_t eriver;
- uint16_t nid;
- uint8_t last_call_end_reason; /* ? */
- uint8_t rssi;
- uint16_t channel;
- uint8_t prev;
- uint16_t pn_offset;
- uint8_t sys_select_pref;
- uint8_t mip_pref;
- uint8_t hybrid_pref;
-} __attribute__ ((packed));
-typedef struct WmcCmdFieldTestRsp WmcCmdFieldTestRsp;
-
-/*****************************************************/
-
-#endif /* LIBWMC_PROTOCOL_H */
diff --git a/libwmc/src/result-private.h b/libwmc/src/result-private.h
deleted file mode 100644
index 1e824e29..00000000
--- a/libwmc/src/result-private.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBWMC_RESULT_PRIVATE_H
-#define LIBWMC_RESULT_PRIVATE_H
-
-#include "result.h"
-
-WmcResult *wmc_result_new (void);
-
-void wmc_result_add_string (WmcResult *result,
- const char *key,
- const char *str);
-
-void wmc_result_add_u8 (WmcResult *result,
- const char *key,
- uint8_t num);
-
-void wmc_result_add_u32 (WmcResult *result,
- const char *key,
- uint32_t num);
-
-#endif /* LIBWMC_RESULT_PRIVATE_H */
diff --git a/libwmc/src/result.c b/libwmc/src/result.c
deleted file mode 100644
index 950cb021..00000000
--- a/libwmc/src/result.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2010 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#include "result.h"
-#include "result-private.h"
-#include "errors.h"
-
-/*********************************************************/
-
-typedef struct Val Val;
-
-typedef enum {
- VAL_TYPE_NONE = 0,
- VAL_TYPE_STRING = 1,
- VAL_TYPE_U8 = 2,
- VAL_TYPE_U32 = 3
-} ValType;
-
-struct Val {
- char *key;
- ValType type;
- union {
- char *s;
- uint8_t u8;
- uint32_t u32;
- } u;
- Val *next;
-};
-
-static void
-val_free (Val *v)
-{
- if (v->type == VAL_TYPE_STRING) {
- if (v->u.s)
- free (v->u.s);
- }
- free (v->key);
- memset (v, 0, sizeof (*v));
- free (v);
-}
-
-static Val *
-val_new_string (const char *key, const char *value)
-{
- Val *v;
-
- wmc_return_val_if_fail (key != NULL, NULL);
- wmc_return_val_if_fail (key[0] != '\0', NULL);
- wmc_return_val_if_fail (value != NULL, NULL);
-
- v = calloc (sizeof (Val), 1);
- if (v == NULL)
- return NULL;
-
- v->key = strdup (key);
- v->type = VAL_TYPE_STRING;
- v->u.s = strdup (value);
- return v;
-}
-
-static Val *
-val_new_u8 (const char *key, uint8_t u)
-{
- Val *v;
-
- wmc_return_val_if_fail (key != NULL, NULL);
- wmc_return_val_if_fail (key[0] != '\0', NULL);
-
- v = calloc (sizeof (Val), 1);
- if (v == NULL)
- return NULL;
-
- v->key = strdup (key);
- v->type = VAL_TYPE_U8;
- v->u.u8 = u;
- return v;
-}
-
-static Val *
-val_new_u32 (const char *key, uint32_t u)
-{
- Val *v;
-
- wmc_return_val_if_fail (key != NULL, NULL);
- wmc_return_val_if_fail (key[0] != '\0', NULL);
-
- v = calloc (sizeof (Val), 1);
- if (v == NULL)
- return NULL;
-
- v->key = strdup (key);
- v->type = VAL_TYPE_U32;
- v->u.u32 = u;
- return v;
-}
-
-/*********************************************************/
-
-struct WmcResult {
- uint32_t refcount;
- Val *first;
-};
-
-WmcResult *
-wmc_result_new (void)
-{
- WmcResult *r;
-
- r = calloc (sizeof (WmcResult), 1);
- if (r)
- r->refcount = 1;
- return r;
-}
-
-WmcResult *
-wmc_result_ref (WmcResult *r)
-{
- wmc_return_val_if_fail (r != NULL, NULL);
- wmc_return_val_if_fail (r->refcount > 0, NULL);
-
- r->refcount++;
- return r;
-}
-
-static void
-wmc_result_free (WmcResult *r)
-{
- Val *v, *n;
-
- v = r->first;
- while (v) {
- n = v->next;
- val_free (v);
- v = n;
- }
- memset (r, 0, sizeof (*r));
- free (r);
-}
-
-void
-wmc_result_unref (WmcResult *r)
-{
- wmc_return_if_fail (r != NULL);
- wmc_return_if_fail (r->refcount > 0);
-
- r->refcount--;
- if (r->refcount == 0)
- wmc_result_free (r);
-}
-
-static Val *
-find_val (WmcResult *r, const char *key, ValType expected_type)
-{
- Val *v, *n;
-
- v = r->first;
- while (v) {
- n = v->next;
- if (strcmp (v->key, key) == 0) {
- /* Check type */
- wmc_return_val_if_fail (v->type == expected_type, NULL);
- return v;
- }
- v = n;
- }
- return NULL;
-}
-
-void
-wmc_result_add_string (WmcResult *r,
- const char *key,
- const char *str)
-{
- Val *v;
-
- wmc_return_if_fail (r != NULL);
- wmc_return_if_fail (r->refcount > 0);
- wmc_return_if_fail (key != NULL);
- wmc_return_if_fail (str != NULL);
-
- v = val_new_string (key, str);
- wmc_return_if_fail (v != NULL);
- v->next = r->first;
- r->first = v;
-}
-
-int
-wmc_result_get_string (WmcResult *r,
- const char *key,
- const char **out_val)
-{
- Val *v;
-
- wmc_return_val_if_fail (r != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (r->refcount > 0, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (key != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (out_val != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (*out_val == NULL, -WMC_ERROR_INVALID_ARGUMENTS);
-
- v = find_val (r, key, VAL_TYPE_STRING);
- if (v == NULL)
- return -WMC_ERROR_VALUE_NOT_FOUND;
-
- *out_val = v->u.s;
- return 0;
-}
-
-void
-wmc_result_add_u8 (WmcResult *r,
- const char *key,
- uint8_t num)
-{
- Val *v;
-
- wmc_return_if_fail (r != NULL);
- wmc_return_if_fail (r->refcount > 0);
- wmc_return_if_fail (key != NULL);
-
- v = val_new_u8 (key, num);
- wmc_return_if_fail (v != NULL);
- v->next = r->first;
- r->first = v;
-}
-
-int
-wmc_result_get_u8 (WmcResult *r,
- const char *key,
- uint8_t *out_val)
-{
- Val *v;
-
- wmc_return_val_if_fail (r != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (r->refcount > 0, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (key != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (out_val != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
-
- v = find_val (r, key, VAL_TYPE_U8);
- if (v == NULL)
- return -WMC_ERROR_VALUE_NOT_FOUND;
-
- *out_val = v->u.u8;
- return 0;
-}
-
-void
-wmc_result_add_u32 (WmcResult *r,
- const char *key,
- uint32_t num)
-{
- Val *v;
-
- wmc_return_if_fail (r != NULL);
- wmc_return_if_fail (r->refcount > 0);
- wmc_return_if_fail (key != NULL);
-
- v = val_new_u32 (key, num);
- wmc_return_if_fail (v != NULL);
- v->next = r->first;
- r->first = v;
-}
-
-int
-wmc_result_get_u32 (WmcResult *r,
- const char *key,
- uint32_t *out_val)
-{
- Val *v;
-
- wmc_return_val_if_fail (r != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (r->refcount > 0, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (key != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
- wmc_return_val_if_fail (out_val != NULL, -WMC_ERROR_INVALID_ARGUMENTS);
-
- v = find_val (r, key, VAL_TYPE_U32);
- if (v == NULL)
- return -WMC_ERROR_VALUE_NOT_FOUND;
-
- *out_val = v->u.u32;
- return 0;
-}
diff --git a/libwmc/src/result.h b/libwmc/src/result.h
deleted file mode 100644
index 1c73711a..00000000
--- a/libwmc/src/result.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2010 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBWMC_RESULT_H
-#define LIBWMC_RESULT_H
-
-#include <stdint.h>
-
-typedef struct WmcResult WmcResult;
-
-int wmc_result_get_string (WmcResult *r,
- const char *key,
- const char **out_val);
-
-int wmc_result_get_u8 (WmcResult *r,
- const char *key,
- uint8_t *out_val);
-
-int wmc_result_get_u32 (WmcResult *r,
- const char *key,
- uint32_t *out_val);
-
-WmcResult *wmc_result_ref (WmcResult *r);
-
-void wmc_result_unref (WmcResult *r);
-
-#endif /* LIBWMC_RESULT_H */
diff --git a/libwmc/src/utils.c b/libwmc/src/utils.c
deleted file mode 100644
index 5539edaf..00000000
--- a/libwmc/src/utils.c
+++ /dev/null
@@ -1,459 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2010 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <fcntl.h>
-#include <string.h>
-
-#include "utils.h"
-#include "errors.h"
-
-/* QCDM protocol frames are pseudo Async HDLC frames which end with a 3-byte
- * trailer. This trailer consists of the 16-bit CRC of the frame plus an ending
- * "async control character" whose value is 0x7E. The frame *and* the CRC are
- * escaped before adding the trailing control character so that the control
- * character (0x7E) and the escape marker (0x7D) are never seen in the frame.
- */
-
-/* Table of CRCs for each possible byte, with a generator polynomial of 0x8408 */
-static const uint16_t crc_table[256] = {
- 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
- 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
- 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
- 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
- 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
- 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
- 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
- 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
- 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
- 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
- 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
- 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
- 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
- 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
- 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
- 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
- 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
- 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
- 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
- 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
- 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
- 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
- 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
- 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
- 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
- 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
- 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
- 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
- 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
- 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
- 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
- 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
-};
-
-/* Calculate the CRC for a buffer using a seed of 0xffff */
-uint16_t
-wmc_crc16 (const char *buffer, size_t len, uint16_t seed)
-{
- uint16_t crc = seed ? seed : 0xFFFF;
-
- while (len--)
- crc = crc_table[(crc ^ *buffer++) & 0xff] ^ (crc >> 8);
- return ~crc;
-}
-
-#define DIAG_ESC_CHAR 0x7D /* Escape sequence 1st character value */
-#define DIAG_ESC_MASK 0x20 /* Escape sequence complement value */
-
-/* Performs DM escaping on inbuf putting the result into outbuf, and returns
- * the final length of the buffer.
- */
-size_t
-hdlc_escape (const char *inbuf,
- size_t inbuf_len,
- wmcbool escape_all_ctrl,
- char *outbuf,
- size_t outbuf_len)
-{
- const char *src = inbuf;
- char *dst = outbuf;
- size_t i = inbuf_len;
-
- wmc_return_val_if_fail (inbuf != NULL, 0);
- wmc_return_val_if_fail (inbuf_len > 0, 0);
- wmc_return_val_if_fail (outbuf != NULL, 0);
- wmc_return_val_if_fail (outbuf_len > inbuf_len, 0);
-
- /* Since escaping potentially doubles the # of bytes, short-circuit the
- * length check if destination buffer is clearly large enough. Note the
- *
- */
- if (outbuf_len <= inbuf_len << 1) {
- size_t outbuf_required = inbuf_len + 1; /* +1 for the trailing control char */
-
- /* Each escaped character takes up two bytes in the output buffer */
- while (i--) {
- if ( *src == DIAG_CONTROL_CHAR
- || *src == DIAG_ESC_CHAR
- || (escape_all_ctrl && *src <= 0x20))
- outbuf_required++;
- src++;
- }
-
- if (outbuf_len < outbuf_required)
- return 0;
- }
-
- /* Do the actual escaping. Replace both the control character and
- * the escape character in the source buffer with the following sequence:
- *
- * <escape_char> <src_byte ^ escape_mask>
- */
- src = inbuf;
- i = inbuf_len;
- while (i--) {
- uint8_t byte = (uint8_t) *src++;
-
- if ( byte == DIAG_CONTROL_CHAR
- || byte == DIAG_ESC_CHAR
- || (escape_all_ctrl && byte <= 0x20)) {
- *dst++ = DIAG_ESC_CHAR;
- *dst++ = byte ^ DIAG_ESC_MASK;
- } else
- *dst++ = byte;
- }
-
- return (dst - outbuf);
-}
-
-size_t
-hdlc_unescape (const char *inbuf,
- size_t inbuf_len,
- char *outbuf,
- size_t outbuf_len,
- wmcbool *escaping)
-{
- size_t i, outsize;
-
- wmc_return_val_if_fail (inbuf_len > 0, 0);
- wmc_return_val_if_fail (outbuf_len >= inbuf_len, 0);
- wmc_return_val_if_fail (escaping != NULL, 0);
-
- for (i = 0, outsize = 0; i < inbuf_len; i++) {
- if (*escaping) {
- outbuf[outsize++] = inbuf[i] ^ DIAG_ESC_MASK;
- *escaping = FALSE;
- } else if (inbuf[i] == DIAG_ESC_CHAR)
- *escaping = TRUE;
- else
- outbuf[outsize++] = inbuf[i];
-
- /* About to overrun output buffer size */
- if (outsize >= outbuf_len)
- return 0;
- }
-
- return outsize;
-}
-
-/**
- * hdlc_encapsulate_buffer:
- * @inbuf: data buffer to encapsulate
- * @cmd_len: size of the data contained in @inbuf
- * @inbuf_len: total size of @inbuf itself (not just the data)
- * @crc_seed: if non-zero, CRC-16 seed to use; if 0, uses standard 0xFFFF
- * @add_trailer: if %TRUE, adds trailing 0x7E
- * @escape_all_ctrl: if %TRUE, escapes all control characters instead of only
- * special HDLC escape characters 0x7D and 0x7E
- * @outbuf: buffer in which to put the encapsulated data
- * @outbuf_len: total size of @outbuf
- *
- * Escapes and CRCs given data using HDLC-style mechanisms, and optionally adds
- * the trailing control character that denotes the end of the HDLC frame.
- *
- * Returns: size of the encapsulated data writted to @outbuf.
- **/
-size_t
-hdlc_encapsulate_buffer (char *inbuf,
- size_t cmd_len,
- size_t inbuf_len,
- uint16_t crc_seed,
- wmcbool add_trailer,
- wmcbool escape_all_ctrl,
- char *outbuf,
- size_t outbuf_len)
-{
- uint16_t crc;
- size_t escaped_len;
-
- wmc_return_val_if_fail (inbuf != NULL, 0);
- wmc_return_val_if_fail (cmd_len >= 1, 0);
- wmc_return_val_if_fail (inbuf_len >= cmd_len + 2, 0); /* space for CRC */
- wmc_return_val_if_fail (outbuf != NULL, 0);
-
- /* Add the CRC */
- crc = wmc_crc16 (inbuf, cmd_len, crc_seed ? crc_seed : 0xFFFF);
- inbuf[cmd_len++] = crc & 0xFF;
- inbuf[cmd_len++] = (crc >> 8) & 0xFF;
-
- escaped_len = hdlc_escape (inbuf, cmd_len, escape_all_ctrl, outbuf, outbuf_len);
- wmc_return_val_if_fail (outbuf_len > escaped_len, 0);
-
- if (add_trailer)
- outbuf[escaped_len++] = DIAG_CONTROL_CHAR;
-
- return escaped_len;
-}
-
-#define AT_WMC_PREFIX "AT*WMC="
-
-/**
- * uml290_wmc_encapsulate:
- * @inbuf: data buffer to encapsulate
- * @cmd_len: size of the data contained in @inbuf
- * @inbuf_len: total size of @inbuf itself (not just the data)
- * @outbuf: buffer in which to put the encapsulated data
- * @outbuf_len: total size of @outbuf
- *
- * Escapes and CRCs given data using HDLC-style mechanisms with UML290 specific
- * quirks.
- *
- * Returns: size of the encapsulated data writted to @outbuf.
- */
-static size_t
-uml290_wmc_encapsulate (char *inbuf,
- size_t cmd_len,
- size_t inbuf_len,
- char *outbuf,
- size_t outbuf_len)
-{
- size_t encap_len;
- size_t estimated_out_len;
-
- wmc_return_val_if_fail (inbuf != NULL, 0);
- wmc_return_val_if_fail (cmd_len >= 1, 0);
- wmc_return_val_if_fail (inbuf_len >= cmd_len + 2, 0); /* space for CRC */
- wmc_return_val_if_fail (outbuf != NULL, 0);
-
- estimated_out_len = cmd_len + strlen (AT_WMC_PREFIX);
- estimated_out_len += 3; /* CRC + trailer */
- estimated_out_len += cmd_len * 2; /* escaping */
- wmc_return_val_if_fail (outbuf_len > estimated_out_len, 0);
-
- memcpy (outbuf, AT_WMC_PREFIX, strlen (AT_WMC_PREFIX));
-
- encap_len = hdlc_encapsulate_buffer (inbuf, cmd_len, inbuf_len, 0xAAFE,
- FALSE, TRUE,
- outbuf + strlen (AT_WMC_PREFIX),
- outbuf_len);
- if (encap_len > 0) {
- encap_len += strlen (AT_WMC_PREFIX);
- outbuf[encap_len++] = 0x0D; /* trailer */
- }
-
- return encap_len;
-}
-
-/**
- * wmc_encapsulate:
- * @inbuf: data buffer to encapsulate
- * @cmd_len: size of the data contained in @inbuf
- * @inbuf_len: total size of @inbuf itself (not just the data)
- * @outbuf: buffer in which to put the encapsulated data
- * @outbuf_len: total size of @outbuf
- * @uml290: if %TRUE return buffer suitable for sending to UML290 devices
- *
- * Escapes and CRCs given data using HDLC-style mechanisms.
- *
- * Returns: size of the encapsulated data writted to @outbuf.
- */
-size_t
-wmc_encapsulate (char *inbuf,
- size_t cmd_len,
- size_t inbuf_len,
- char *outbuf,
- size_t outbuf_len,
- wmcbool uml290)
-{
- wmc_return_val_if_fail (inbuf != NULL, 0);
- wmc_return_val_if_fail (cmd_len >= 1, 0);
- wmc_return_val_if_fail (inbuf_len >= cmd_len + 3, 0); /* space for CRC + trailer */
- wmc_return_val_if_fail (outbuf != NULL, 0);
-
- if (uml290)
- return uml290_wmc_encapsulate (inbuf, cmd_len, inbuf_len, outbuf, outbuf_len);
-
- /* Otherwise do normal WMC */
- return hdlc_encapsulate_buffer (inbuf, cmd_len, inbuf_len,
- 0, TRUE, FALSE, outbuf, outbuf_len);
-}
-
-/**
- * hdlc_decapsulate_buffer:
- * @inbuf: buffer in which to look for an HDLC frame
- * @inbuf_len: length of valid data in @inbuf
- * @check_known_crc: if %TRUE, validate the CRC using @known_crc if the normal
- * CRC check fails
- * @known_crc: if @check_known_crc is %TRUE, compare the frame's CRC against
- * @known_crc if the normal CRC check fails. @known_crc must be in Little
- * Endian (LE) byte order.
- * @outbuf: buffer in which to put decapsulated data from the HDLC frame
- * @outbuf_len: max size of @outbuf
- * @out_decap_len: on success, size of the decapsulated data
- * @out_used: on either success or failure, amount of data used; caller should
- * discard this much data from @inbuf before the next call to this function
- * @out_need_more: when TRUE, indicates that more data is required before
- * a determination about a valid HDLC frame can be made; caller should add
- * more data to @inbuf before calling this function again.
- *
- * Attempts to retrieve, unescape, and CRC-check an HDLC frame from the given
- * buffer.
- *
- * Returns: FALSE on error (packet was invalid or malformed, or the CRC check
- * failed, etc) and places number of bytes to discard from @inbuf in @out_used.
- * When TRUE, either more data is required (in which case @out_need_more will
- * be TRUE), or a data packet was successfully retrieved from @inbuf and the
- * decapsulated packet of length @out_decap_len was placed into @outbuf. In
- * all cases the caller should advance the buffer by the number of bytes
- * returned in @out_used before calling this function again.
- **/
-wmcbool
-hdlc_decapsulate_buffer (const char *inbuf,
- size_t inbuf_len,
- wmcbool check_known_crc,
- uint16_t known_crc,
- char *outbuf,
- size_t outbuf_len,
- size_t *out_decap_len,
- size_t *out_used,
- wmcbool *out_need_more)
-{
- wmcbool escaping = FALSE;
- size_t i, pkt_len = 0, unesc_len;
- uint16_t crc, pkt_crc;
-
- wmc_return_val_if_fail (inbuf != NULL, FALSE);
- wmc_return_val_if_fail (outbuf != NULL, FALSE);
- wmc_return_val_if_fail (outbuf_len > 0, FALSE);
- wmc_return_val_if_fail (out_decap_len != NULL, FALSE);
- wmc_return_val_if_fail (out_used != NULL, FALSE);
- wmc_return_val_if_fail (out_need_more != NULL, FALSE);
-
- *out_decap_len = 0;
- *out_used = 0;
- *out_need_more = FALSE;
-
- if (inbuf_len < 4) {
- *out_need_more = TRUE;
- return TRUE;
- }
-
- /* Find the async control character */
- for (i = 0; i < inbuf_len; i++) {
- if (inbuf[i] == DIAG_CONTROL_CHAR) {
- /* If the control character shows up in a position before a valid
- * QCDM packet length (4), the packet is malformed.
- */
- if (i < 3) {
- /* Tell the caller to advance the buffer past the control char */
- *out_used = i + 1;
- return FALSE;
- }
-
- pkt_len = i;
- break;
- }
- }
-
- /* No control char yet, need more data */
- if (!pkt_len) {
- *out_need_more = TRUE;
- return TRUE;
- }
-
- /* Unescape first; note that pkt_len */
- unesc_len = hdlc_unescape (inbuf, pkt_len, outbuf, outbuf_len, &escaping);
- if (!unesc_len) {
- /* Tell the caller to advance the buffer past the control char */
- *out_used = pkt_len + 1;
- return FALSE;
- }
-
- if (escaping) {
- *out_need_more = TRUE;
- return TRUE;
- }
-
- /* Check the CRC of the packet's data */
- crc = wmc_crc16 (outbuf, unesc_len - 2, 0);
- pkt_crc = outbuf[unesc_len - 2] & 0xFF;
- pkt_crc |= (outbuf[unesc_len - 1] & 0xFF) << 8;
- if (crc != pkt_crc) {
- if (!check_known_crc || (pkt_crc != known_crc)) {
- *out_used = pkt_len + 1; /* packet + CRC + 0x7E */
- return FALSE;
- }
- }
-
- *out_used = pkt_len + 1; /* packet + CRC + 0x7E */
- *out_decap_len = unesc_len - 2; /* decap_len should not include the CRC */
- return TRUE;
-}
-
-/**
- * wmc_decapsulate:
- * @inbuf: buffer in which to look for an HDLC frame
- * @inbuf_len: length of valid data in @inbuf
- * @outbuf: buffer in which to put decapsulated data from the HDLC frame
- * @outbuf_len: max size of @outbuf
- * @out_decap_len: on success, size of the decapsulated data
- * @out_used: on either success or failure, amount of data used; caller should
- * discard this much data from @inbuf before the next call to this function
- * @out_need_more: when TRUE, indicates that more data is required before
- * a determination about a valid HDLC frame can be made; caller should add
- * more data to @inbuf before calling this function again.
- * @uml290: if %TRUE decapsulate response from UML290 devices
- *
- * Attempts to retrieve, unescape, and CRC-check an HDLC frame from the given
- * buffer.
- *
- * Returns: FALSE on error (packet was invalid or malformed, or the CRC check
- * failed, etc) and places number of bytes to discard from @inbuf in @out_used.
- * When TRUE, either more data is required (in which case @out_need_more will
- * be TRUE), or a data packet was successfully retrieved from @inbuf and the
- * decapsulated packet of length @out_decap_len was placed into @outbuf. In
- * all cases the caller should advance the buffer by the number of bytes
- * returned in @out_used before calling this function again.
- **/
-wmcbool
-wmc_decapsulate (const char *inbuf,
- size_t inbuf_len,
- char *outbuf,
- size_t outbuf_len,
- size_t *out_decap_len,
- size_t *out_used,
- wmcbool *out_need_more,
- wmcbool uml290)
-{
- return hdlc_decapsulate_buffer (inbuf, inbuf_len,
- uml290, uml290 ? 0x3030 : 0,
- outbuf, outbuf_len,
- out_decap_len, out_used, out_need_more);
-}
diff --git a/libwmc/src/utils.h b/libwmc/src/utils.h
deleted file mode 100644
index 0918c29c..00000000
--- a/libwmc/src/utils.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright (C) 2011 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBWMC_UTILS_H
-#define LIBWMC_UTILS_H
-
-#include <stdint.h>
-
-typedef uint8_t wmcbool;
-#ifndef TRUE
-#define TRUE ((uint8_t) 1)
-#endif
-#ifndef FALSE
-#define FALSE ((uint8_t) 0)
-#endif
-
-#define DIAG_CONTROL_CHAR 0x7E
-#define DIAG_TRAILER_LEN 3
-
-/* Utility and testcase functions */
-
-uint16_t wmc_crc16 (const char *buffer, size_t len, uint16_t seed);
-
-size_t hdlc_escape (const char *inbuf,
- size_t inbuf_len,
- wmcbool escape_all_ctrl,
- char *outbuf,
- size_t outbuf_len);
-
-size_t hdlc_unescape (const char *inbuf,
- size_t inbuf_len,
- char *outbuf,
- size_t outbuf_len,
- wmcbool *escaping);
-
-size_t hdlc_encapsulate_buffer (char *inbuf,
- size_t cmd_len,
- size_t inbuf_len,
- uint16_t crc_seed,
- wmcbool add_trailer,
- wmcbool escape_all_ctrl,
- char *outbuf,
- size_t outbuf_len);
-
-wmcbool hdlc_decapsulate_buffer (const char *inbuf,
- size_t inbuf_len,
- wmcbool check_known_crc,
- uint16_t known_crc,
- char *outbuf,
- size_t outbuf_len,
- size_t *out_decap_len,
- size_t *out_used,
- wmcbool *out_need_more);
-
-/* Functions for actual communication */
-
-size_t wmc_encapsulate (char *inbuf,
- size_t cmd_len,
- size_t inbuf_len,
- char *outbuf,
- size_t outbuf_len,
- wmcbool uml290);
-
-wmcbool wmc_decapsulate (const char *inbuf,
- size_t inbuf_len,
- char *outbuf,
- size_t outbuf_len,
- size_t *out_decap_len,
- size_t *out_used,
- wmcbool *out_need_more,
- wmcbool uml290);
-
-#endif /* LIBWMC_UTILS_H */