| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* qmicli -- Command line interface to control QMI devices |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Copyright (C) 2015 Velocloud Inc. |
| 19 |
* Copyright (C) 2012-2017 Aleksander Morgado <[email protected]> |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <glib.h> |
| 23 |
|
| 24 |
#include <libqmi-glib.h> |
| 25 |
|
| 26 |
#ifndef __QMICLI_HELPERS_H__ |
| 27 |
#define __QMICLI_HELPERS_H__ |
| 28 |
|
| 29 |
/* Common helpers to read enums from strings */ |
| 30 |
#define QMICLI_ENUM_LIST \ |
| 31 |
QMICLI_ENUM_LIST_ITEM (QmiDmsOperatingMode, dms_operating_mode, "operating mode") \ |
| 32 |
QMICLI_ENUM_LIST_ITEM (QmiDmsUimFacility, dms_uim_facility, "facility") \ |
| 33 |
QMICLI_ENUM_LIST_ITEM (QmiPdcConfigurationType, pdc_configuration_type, "configuration type") \ |
| 34 |
QMICLI_ENUM_LIST_ITEM (QmiNasRadioInterface, nas_radio_interface, "radio interface") \ |
| 35 |
QMICLI_ENUM_LIST_ITEM (QmiDeviceExpectedDataFormat, device_expected_data_format, "device expected data format") \ |
| 36 |
QMICLI_ENUM_LIST_ITEM (QmiWdaLinkLayerProtocol, wda_link_layer_protocol, "link layer protocol") \ |
| 37 |
QMICLI_ENUM_LIST_ITEM (QmiWdaDataAggregationProtocol, wda_data_aggregation_protocol, "data aggregation protocol") \ |
| 38 |
QMICLI_ENUM_LIST_ITEM (QmiWdaLoopBackState, wda_loop_back_state, "loopback state") \ |
| 39 |
QMICLI_ENUM_LIST_ITEM (QmiDataEndpointType, data_endpoint_type, "data endpoint type") \ |
| 40 |
QMICLI_ENUM_LIST_ITEM (QmiWdsAutoconnectSetting, wds_autoconnect_setting, "autoconnect setting") \ |
| 41 |
QMICLI_ENUM_LIST_ITEM (QmiWdsAutoconnectSettingRoaming, wds_autoconnect_setting_roaming, "autoconnect setting roaming") \ |
| 42 |
QMICLI_ENUM_LIST_ITEM (QmiDmsBootImageDownloadMode, dms_boot_image_download_mode, "boot image download mode") \ |
| 43 |
QMICLI_ENUM_LIST_ITEM (QmiDmsHpDeviceMode, dms_hp_device_mode, "hp device mode") \ |
| 44 |
QMICLI_ENUM_LIST_ITEM (QmiDmsSwiUsbComposition, dms_swi_usb_composition, "swi usb composition") \ |
| 45 |
QMICLI_ENUM_LIST_ITEM (QmiDmsFoxconnDeviceMode, dms_foxconn_device_mode, "foxconn device mode") \ |
| 46 |
QMICLI_ENUM_LIST_ITEM (QmiDmsFoxconnFirmwareVersionType, dms_foxconn_firmware_version_type, "foxconn firmware version type") \ |
| 47 |
QMICLI_ENUM_LIST_ITEM (QmiUimSessionType, uim_session_type, "session type") \ |
| 48 |
QMICLI_ENUM_LIST_ITEM (QmiDsdApnType, dsd_apn_type, "apn type") \ |
| 49 |
QMICLI_ENUM_LIST_ITEM (QmiDmsMacType, dms_mac_type, "mac address type") \ |
| 50 |
QMICLI_ENUM_LIST_ITEM (QmiSarRfState, sar_rf_state, "sar rf state") \ |
| 51 |
QMICLI_ENUM_LIST_ITEM (QmiSioPort, sio_port, "sio port") \ |
| 52 |
QMICLI_ENUM_LIST_ITEM (QmiLocOperationMode, loc_operation_mode, "operation mode") \ |
| 53 |
QMICLI_ENUM_LIST_ITEM (QmiLocLockType, loc_lock_type, "lock type") \ |
| 54 |
QMICLI_ENUM_LIST_ITEM (QmiUimCardApplicationPersonalizationFeature, uim_card_application_personalization_feature, "personalization feature" ) \ |
| 55 |
QMICLI_ENUM_LIST_ITEM (QmiUimDepersonalizationOperation, uim_depersonalization_operation, "depersonalization operation" ) \ |
| 56 |
QMICLI_ENUM_LIST_ITEM (QmiWmsMessageType, wms_message_type, "message type" ) \ |
| 57 |
QMICLI_ENUM_LIST_ITEM (QmiWmsMessageClass, wms_message_class, "message class" ) \ |
| 58 |
QMICLI_ENUM_LIST_ITEM (QmiWmsStorageType, wms_storage_type, "storage type" ) \ |
| 59 |
QMICLI_ENUM_LIST_ITEM (QmiWmsReceiptAction, wms_receipt_action, "receipt action" ) \ |
| 60 |
QMICLI_ENUM_LIST_ITEM (QmiFoxFirmwareVersionType, fox_firmware_version_type, "fox firmware version type") \ |
| 61 |
QMICLI_ENUM_LIST_ITEM (QmiGasFirmwareAutoSimMode, gas_firmware_auto_sim_mode, "gas firmware auto sim mode") |
| 62 |
|
| 63 |
#define QMICLI_ENUM_LIST_ITEM(TYPE,TYPE_UNDERSCORE,DESCR) \ |
| 64 |
gboolean qmicli_read_## TYPE_UNDERSCORE ##_from_string (const gchar *str, TYPE *out); |
| 65 |
QMICLI_ENUM_LIST |
| 66 |
#undef QMICLI_ENUM_LIST_ITEM |
| 67 |
|
| 68 |
/* Common helpers to read flags from strings */ |
| 69 |
#define QMICLI_FLAGS_LIST \ |
| 70 |
QMICLI_FLAGS_LIST_ITEM (QmiDeviceOpenFlags, device_open_flags, "device open flags") \ |
| 71 |
QMICLI_FLAGS_LIST_ITEM (QmiDeviceAddLinkFlags, device_add_link_flags, "device add link flags") \ |
| 72 |
QMICLI_FLAGS_LIST_ITEM (QmiLocNmeaType, loc_nmea_type, "NMEA type") \ |
| 73 |
QMICLI_FLAGS_LIST_ITEM (QmiNasPlmnAccessTechnologyIdentifier, nas_plmn_access_technology_identifier, "PLMN access technology") \ |
| 74 |
QMICLI_FLAGS_LIST_ITEM (QmiNasNetworkScanType, nas_network_scan_type, "network scan type") |
| 75 |
|
| 76 |
#define QMICLI_FLAGS_LIST_ITEM(TYPE,TYPE_UNDERSCORE,DESCR) \ |
| 77 |
gboolean qmicli_read_## TYPE_UNDERSCORE ##_from_string (const gchar *str, TYPE *out); |
| 78 |
QMICLI_FLAGS_LIST |
| 79 |
#undef QMICLI_FLAGS_LIST_ITEM |
| 80 |
|
| 81 |
/* Common helpers to read 64bit flags from strings */ |
| 82 |
#define QMICLI_FLAGS64_LIST \ |
| 83 |
QMICLI_FLAGS64_LIST_ITEM (QmiDsdApnTypePreference, dsd_apn_type_preference, "apn type preference") \ |
| 84 |
QMICLI_FLAGS64_LIST_ITEM (QmiWdsApnTypeMask, wds_apn_type_mask, "apn type mask") |
| 85 |
|
| 86 |
#define QMICLI_FLAGS64_LIST_ITEM(TYPE,TYPE_UNDERSCORE,DESCR) \ |
| 87 |
gboolean qmicli_read_## TYPE_UNDERSCORE ##_from_string (const gchar *str, TYPE *out); |
| 88 |
QMICLI_FLAGS64_LIST |
| 89 |
#undef QMICLI_FLAGS64_LIST_ITEM |
| 90 |
|
| 91 |
gchar *qmicli_get_raw_data_printable (const GArray *data, |
| 92 |
gsize max_line_length, |
| 93 |
const gchar *new_line_prefix); |
| 94 |
|
| 95 |
gchar *qmicli_get_firmware_image_unique_id_printable (const GArray *unique_id); |
| 96 |
|
| 97 |
gboolean qmicli_read_dms_uim_pin_id_from_string (const gchar *str, |
| 98 |
QmiDmsUimPinId *out); |
| 99 |
gboolean qmicli_read_uim_pin_id_from_string (const gchar *str, |
| 100 |
QmiUimPinId *out); |
| 101 |
gboolean qmicli_read_ssp_rat_options_from_string (const gchar *str, |
| 102 |
QmiNasRatModePreference *out_mode_preference, |
| 103 |
GArray **out_acquisition_order); |
| 104 |
gboolean qmicli_read_ssp_net_options_from_string (const gchar *str, |
| 105 |
QmiNasNetworkSelectionPreference *out_network_preference, |
| 106 |
guint16 *out_network_mcc, |
| 107 |
guint16 *out_network_mnc); |
| 108 |
gboolean qmicli_read_parse_3gpp_mcc_mnc (const gchar *str, |
| 109 |
guint16 *out_mcc, |
| 110 |
guint16 *out_mnc, |
| 111 |
gboolean *out_pcs_digit); |
| 112 |
gboolean qmicli_read_enable_disable_from_string (const gchar *str, |
| 113 |
gboolean *out); |
| 114 |
gboolean qmicli_read_firmware_id_from_string (const gchar *str, |
| 115 |
QmiDmsFirmwareImageType *out_type, |
| 116 |
guint *out_index); |
| 117 |
gboolean qmicli_read_binary_array_from_string (const gchar *str, |
| 118 |
GArray **out); |
| 119 |
gboolean qmicli_read_cbs_channels_from_string (const gchar *str, |
| 120 |
GArray **out_channels); |
| 121 |
gboolean qmicli_read_authentication_from_string (const gchar *str, |
| 122 |
QmiWdsAuthentication *out); |
| 123 |
gboolean qmicli_read_pdp_type_from_string (const gchar *str, |
| 124 |
QmiWdsPdpType *out); |
| 125 |
gboolean qmicli_read_non_empty_string (const gchar *str, |
| 126 |
const gchar *description, |
| 127 |
gchar **out); |
| 128 |
gboolean qmicli_read_uint_from_string (const gchar *str, |
| 129 |
guint *out); |
| 130 |
gboolean qmicli_read_raw_data_from_string (const gchar *str, |
| 131 |
GArray **out); |
| 132 |
gboolean qmicli_read_yes_no_from_string (const gchar *str, |
| 133 |
gboolean *out); |
| 134 |
|
| 135 |
gchar *qmicli_get_supported_messages_list (const guint8 *data, |
| 136 |
gsize len); |
| 137 |
|
| 138 |
const char *qmicli_earfcn_to_eutra_band_string (guint16 earfcn); |
| 139 |
|
| 140 |
gboolean qmicli_validate_device_open_flags (QmiDeviceOpenFlags mask); |
| 141 |
|
| 142 |
typedef gboolean (*QmiParseKeyValueForeachFn) (const gchar *key, |
| 143 |
const gchar *value, |
| 144 |
GError **error, |
| 145 |
gpointer user_data); |
| 146 |
|
| 147 |
gboolean qmicli_parse_key_value_string (const gchar *str, |
| 148 |
GError **error, |
| 149 |
QmiParseKeyValueForeachFn callback, |
| 150 |
gpointer user_data); |
| 151 |
|
| 152 |
#endif /* __QMICLI_H__ */ |