diff options
-rw-r--r-- | src/qmicli/qmicli-dms.c | 18 | ||||
-rw-r--r-- | src/qmicli/qmicli-helpers.c | 341 | ||||
-rw-r--r-- | src/qmicli/qmicli-helpers.h | 23 | ||||
-rw-r--r-- | src/qmicli/qmicli-nas.c | 2 | ||||
-rw-r--r-- | src/qmicli/qmicli-wda.c | 8 | ||||
-rw-r--r-- | src/qmicli/qmicli-wds.c | 4 | ||||
-rw-r--r-- | src/qmicli/qmicli.c | 2 |
7 files changed, 65 insertions, 333 deletions
diff --git a/src/qmicli/qmicli-dms.c b/src/qmicli/qmicli-dms.c index e9876cd1..a459f054 100644 --- a/src/qmicli/qmicli-dms.c +++ b/src/qmicli/qmicli-dms.c @@ -1254,7 +1254,7 @@ uim_get_ck_status_input_create (const gchar *str) QmiMessageDmsUimGetCkStatusInput *input = NULL; QmiDmsUimFacility facility; - if (qmicli_read_facility_from_string (str, &facility)) { + if (qmicli_read_dms_uim_facility_from_string (str, &facility)) { GError *error = NULL; input = qmi_message_dms_uim_get_ck_status_input_new (); @@ -1345,7 +1345,7 @@ uim_set_ck_protection_input_create (const gchar *str) * "[(facility),disable,(key)]" */ split = g_strsplit (str, ",", -1); - if (qmicli_read_facility_from_string (split[0], &facility) && + if (qmicli_read_dms_uim_facility_from_string (split[0], &facility) && qmicli_read_enable_disable_from_string (split[1], &enable_disable) && qmicli_read_non_empty_string (split[2], "control key", &key)) { @@ -1431,7 +1431,7 @@ uim_unblock_ck_input_create (const gchar *str) * "[(facility),(key)]" */ split = g_strsplit (str, ",", -1); - if (qmicli_read_facility_from_string (split[0], &facility) && + if (qmicli_read_dms_uim_facility_from_string (split[0], &facility) && qmicli_read_non_empty_string (split[1], "control key", &key)) { GError *error = NULL; @@ -1588,7 +1588,7 @@ set_operating_mode_input_create (const gchar *str) QmiMessageDmsSetOperatingModeInput *input = NULL; QmiDmsOperatingMode mode; - if (qmicli_read_operating_mode_from_string (str, &mode)) { + if (qmicli_read_dms_operating_mode_from_string (str, &mode)) { GError *error = NULL; input = qmi_message_dms_set_operating_mode_input_new (); @@ -3276,7 +3276,7 @@ set_boot_image_download_mode_input_create (const gchar *str) * Format of the string is: * [normal|boot-and-recovery] */ - if (!qmicli_read_boot_image_download_mode_from_string (str, &mode)) + if (!qmicli_read_dms_boot_image_download_mode_from_string (str, &mode)) return NULL; input = qmi_message_dms_set_boot_image_download_mode_input_new (); @@ -3429,7 +3429,7 @@ hp_change_device_mode_input_create (const gchar *str) QmiDmsHpDeviceMode mode; GError *error = NULL; - if (!qmicli_read_hp_device_mode_from_string (str, &mode)) { + if (!qmicli_read_dms_hp_device_mode_from_string (str, &mode)) { g_printerr ("error: couldn't parse input HP device mode : '%s'\n", str); return NULL; } @@ -3647,7 +3647,7 @@ swi_set_usb_composition_input_create (const gchar *str) QmiDmsSwiUsbComposition value; GError *error = NULL; - if (!qmicli_read_swi_usb_composition_from_string (str, &value)) + if (!qmicli_read_dms_swi_usb_composition_from_string (str, &value)) return NULL; input = qmi_message_dms_swi_set_usb_composition_input_new (); @@ -3668,7 +3668,7 @@ dell_change_device_mode_input_create (const gchar *str) QmiDmsDellDeviceMode mode; GError *error = NULL; - if (!qmicli_read_dell_device_mode_from_string (str, &mode)) { + if (!qmicli_read_dms_dell_device_mode_from_string (str, &mode)) { g_printerr ("error: couldn't parse input dell device mode : '%s'\n", str); return NULL; } @@ -3726,7 +3726,7 @@ dell_get_firmware_version_input_create (const gchar *str) QmiDmsDellFirmwareVersionType type; GError *error = NULL; - if (!qmicli_read_dell_firmware_version_type_from_string (str, &type)) { + if (!qmicli_read_dms_dell_firmware_version_type_from_string (str, &type)) { g_printerr ("error: couldn't parse input dell firmware version type : '%s'\n", str); return NULL; } diff --git a/src/qmicli/qmicli-helpers.c b/src/qmicli/qmicli-helpers.c index 20441c5f..8f76a545 100644 --- a/src/qmicli/qmicli-helpers.c +++ b/src/qmicli/qmicli-helpers.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Copyright (C) 2015 Velocloud Inc. - * Copyright (C) 2012-2017 Aleksander Morgado <aleksander@aleksander.es> + * Copyright (C) 2012-2019 Aleksander Morgado <aleksander@aleksander.es> */ #include <stdio.h> @@ -26,6 +26,30 @@ #include "qmicli-helpers.h" +#define QMICLI_ENUM_LIST_ITEM(TYPE,TYPE_UNDERSCORE,DESCR) \ + gboolean \ + qmicli_read_## TYPE_UNDERSCORE ##_from_string (const gchar *str, \ + TYPE *out) \ + { \ + GType type; \ + GEnumClass *enum_class; \ + GEnumValue *enum_value; \ + \ + type = qmi_## TYPE_UNDERSCORE ##_get_type (); \ + enum_class = G_ENUM_CLASS (g_type_class_ref (type)); \ + enum_value = g_enum_get_value_by_nick (enum_class, str); \ + \ + if (enum_value) \ + *out = (TYPE)enum_value->value; \ + else \ + g_printerr ("error: invalid " DESCR " value given: '%s'\n", str); \ + \ + g_type_class_unref (enum_class); \ + return !!enum_value; \ + } +QMICLI_ENUM_LIST +#undef QMICLI_ENUM_LIST_ITEM + gchar * qmicli_get_raw_data_printable (const GArray *data, gsize max_line_length, @@ -204,27 +228,6 @@ qmicli_read_uim_pin_id_from_string (const gchar *str, } gboolean -qmicli_read_operating_mode_from_string (const gchar *str, - QmiDmsOperatingMode *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_dms_operating_mode_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDmsOperatingMode)enum_value->value; - else - g_printerr ("error: invalid operating mode value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean qmicli_read_ssp_options_from_string (const gchar *str, QmiNasRatModePreference *out_mode_preference, GArray **out_acquisition_order) @@ -291,27 +294,6 @@ qmicli_read_ssp_options_from_string (const gchar *str, } gboolean -qmicli_read_facility_from_string (const gchar *str, - QmiDmsUimFacility *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_dms_uim_facility_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDmsUimFacility)enum_value->value; - else - g_printerr ("error: invalid facility value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean qmicli_read_enable_disable_from_string (const gchar *str, gboolean *out) { @@ -426,48 +408,6 @@ qmicli_read_binary_array_from_string (const gchar *str, } gboolean -qmicli_read_pdc_configuration_type_from_string (const gchar *str, - QmiPdcConfigurationType *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_pdc_configuration_type_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiPdcConfigurationType)enum_value->value; - else - g_printerr ("error: invalid configuration type value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_radio_interface_from_string (const gchar *str, - QmiNasRadioInterface *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_nas_radio_interface_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiNasRadioInterface)enum_value->value; - else - g_printerr ("error: invalid radio interface value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean qmicli_read_net_open_flags_from_string (const gchar *str, QmiDeviceOpenFlags *out) { @@ -532,132 +472,6 @@ qmicli_read_net_open_flags_from_string (const gchar *str, } gboolean -qmicli_read_expected_data_format_from_string (const gchar *str, - QmiDeviceExpectedDataFormat *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_device_expected_data_format_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDeviceExpectedDataFormat)enum_value->value; - else - g_printerr ("error: invalid expected data format value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_link_layer_protocol_from_string (const gchar *str, - QmiWdaLinkLayerProtocol *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_wda_link_layer_protocol_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiWdaLinkLayerProtocol)enum_value->value; - else - g_printerr ("error: invalid link layer protocol value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_data_aggregation_protocol_from_string (const gchar *str, - QmiWdaDataAggregationProtocol *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_wda_data_aggregation_protocol_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiWdaDataAggregationProtocol)enum_value->value; - else - g_printerr ("error: invalid data aggregation protocol value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_data_endpoint_type_from_string (const gchar *str, - QmiDataEndpointType *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_data_endpoint_type_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDataEndpointType)enum_value->value; - else - g_printerr ("error: invalid data aggregation protocol value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_autoconnect_setting_from_string (const gchar *str, - QmiWdsAutoconnectSetting *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_wds_autoconnect_setting_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiWdsAutoconnectSetting)enum_value->value; - else - g_printerr ("error: invalid autoconnect setting value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_autoconnect_setting_roaming_from_string (const gchar *str, - QmiWdsAutoconnectSettingRoaming *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_wds_autoconnect_setting_roaming_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiWdsAutoconnectSettingRoaming)enum_value->value; - else - g_printerr ("error: invalid autoconnect setting roaming value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean qmicli_read_authentication_from_string (const gchar *str, QmiWdsAuthentication *out) { @@ -694,111 +508,6 @@ qmicli_read_pdp_type_from_string (const gchar *str, } gboolean -qmicli_read_boot_image_download_mode_from_string (const gchar *str, - QmiDmsBootImageDownloadMode *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_dms_boot_image_download_mode_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDmsBootImageDownloadMode)enum_value->value; - else - g_printerr ("error: invalid boot image download mode value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_hp_device_mode_from_string (const gchar *str, - QmiDmsHpDeviceMode *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_dms_hp_device_mode_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDmsHpDeviceMode)enum_value->value; - else - g_printerr ("error: invalid HP device mode value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_swi_usb_composition_from_string (const gchar *str, - QmiDmsSwiUsbComposition *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_dms_swi_usb_composition_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDmsSwiUsbComposition)enum_value->value; - else - g_printerr ("error: invalid SWI USB Composition value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_dell_device_mode_from_string (const gchar *str, - QmiDmsDellDeviceMode *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_dms_dell_device_mode_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDmsDellDeviceMode)enum_value->value; - else - g_printerr ("error: invalid Dell device mode value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean -qmicli_read_dell_firmware_version_type_from_string (const gchar *str, - QmiDmsDellFirmwareVersionType *out) -{ - GType type; - GEnumClass *enum_class; - GEnumValue *enum_value; - - type = qmi_dms_dell_firmware_version_type_get_type (); - enum_class = G_ENUM_CLASS (g_type_class_ref (type)); - enum_value = g_enum_get_value_by_nick (enum_class, str); - - if (enum_value) - *out = (QmiDmsDellFirmwareVersionType)enum_value->value; - else - g_printerr ("error: invalid Dell firmware version type value given: '%s'\n", str); - - g_type_class_unref (enum_class); - return !!enum_value; -} - -gboolean qmicli_read_uint_from_string (const gchar *str, guint *out) { diff --git a/src/qmicli/qmicli-helpers.h b/src/qmicli/qmicli-helpers.h index 439e1e4b..5dbfdfe8 100644 --- a/src/qmicli/qmicli-helpers.h +++ b/src/qmicli/qmicli-helpers.h @@ -26,6 +26,29 @@ #ifndef __QMICLI_HELPERS_H__ #define __QMICLI_HELPERS_H__ +/* Common helpers to read enums from strings */ +#define QMICLI_ENUM_LIST \ + QMICLI_ENUM_LIST_ITEM (QmiDmsOperatingMode, dms_operating_mode, "operating mode") \ + QMICLI_ENUM_LIST_ITEM (QmiDmsUimFacility, dms_uim_facility, "facility") \ + QMICLI_ENUM_LIST_ITEM (QmiPdcConfigurationType, pdc_configuration_type, "configuration type") \ + QMICLI_ENUM_LIST_ITEM (QmiNasRadioInterface, nas_radio_interface, "radio interface") \ + QMICLI_ENUM_LIST_ITEM (QmiDeviceExpectedDataFormat, device_expected_data_format, "device expected data format") \ + QMICLI_ENUM_LIST_ITEM (QmiWdaLinkLayerProtocol, wda_link_layer_protocol, "link layer protocol") \ + QMICLI_ENUM_LIST_ITEM (QmiWdaDataAggregationProtocol, wda_data_aggregation_protocol, "data aggregation protocol") \ + QMICLI_ENUM_LIST_ITEM (QmiDataEndpointType, data_endpoint_type, "data endpoint type") \ + QMICLI_ENUM_LIST_ITEM (QmiWdsAutoconnectSetting, wds_autoconnect_setting, "autoconnect setting") \ + QMICLI_ENUM_LIST_ITEM (QmiWdsAutoconnectSettingRoaming, wds_autoconnect_setting_roaming, "autoconnect setting roaming") \ + QMICLI_ENUM_LIST_ITEM (QmiDmsBootImageDownloadMode, dms_boot_image_download_mode, "boot image download mode") \ + QMICLI_ENUM_LIST_ITEM (QmiDmsHpDeviceMode, dms_hp_device_mode, "hp device mode") \ + QMICLI_ENUM_LIST_ITEM (QmiDmsSwiUsbComposition, dms_swi_usb_composition, "swi usb composition") \ + QMICLI_ENUM_LIST_ITEM (QmiDmsDellDeviceMode, dms_dell_device_mode, "dell device mode") \ + QMICLI_ENUM_LIST_ITEM (QmiDmsDellFirmwareVersionType, dms_dell_firmware_version_type, "dell firmware version type") + +#define QMICLI_ENUM_LIST_ITEM(TYPE,TYPE_UNDERSCORE,DESCR) \ + gboolean qmicli_read_## TYPE_UNDERSCORE ##_from_string (const gchar *str, TYPE *out); +QMICLI_ENUM_LIST +#undef QMICLI_ENUM_LIST_ITEM + gchar *qmicli_get_raw_data_printable (const GArray *data, gsize max_line_length, const gchar *new_line_prefix); diff --git a/src/qmicli/qmicli-nas.c b/src/qmicli/qmicli-nas.c index 01b4ab02..e8f85a41 100644 --- a/src/qmicli/qmicli-nas.c +++ b/src/qmicli/qmicli-nas.c @@ -673,7 +673,7 @@ get_tx_rx_info_input_create (const gchar *str, g_assert (interface != NULL); - if (qmicli_read_radio_interface_from_string (str, interface)) { + if (qmicli_read_nas_radio_interface_from_string (str, interface)) { GError *error = NULL; input = qmi_message_nas_get_tx_rx_info_input_new (); diff --git a/src/qmicli/qmicli-wda.c b/src/qmicli/qmicli-wda.c index 9df3d4b4..cf6d0ed9 100644 --- a/src/qmicli/qmicli-wda.c +++ b/src/qmicli/qmicli-wda.c @@ -328,7 +328,7 @@ set_data_format_properties_handle (const gchar *key, } if (g_ascii_strcasecmp (key, "link-layer-protocol") == 0) { - if (!qmicli_read_link_layer_protocol_from_string (value, &(props->link_layer_protocol))) { + if (!qmicli_read_wda_link_layer_protocol_from_string (value, &(props->link_layer_protocol))) { g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED, @@ -340,7 +340,7 @@ set_data_format_properties_handle (const gchar *key, } if (g_ascii_strcasecmp (key, "ul-protocol") == 0) { - if (!qmicli_read_data_aggregation_protocol_from_string (value, &(props->ul_protocol))) { + if (!qmicli_read_wda_data_aggregation_protocol_from_string (value, &(props->ul_protocol))) { g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED, @@ -352,7 +352,7 @@ set_data_format_properties_handle (const gchar *key, } if (g_ascii_strcasecmp (key, "dl-protocol") == 0) { - if (!qmicli_read_data_aggregation_protocol_from_string (value, &(props->dl_protocol))) { + if (!qmicli_read_wda_data_aggregation_protocol_from_string (value, &(props->dl_protocol))) { g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED, @@ -505,7 +505,7 @@ set_data_format_input_create (const gchar *str) * "[(raw-ip|802-3)]" */ else { - if (!qmicli_read_link_layer_protocol_from_string (str, &(props.link_layer_protocol))) { + if (!qmicli_read_wda_link_layer_protocol_from_string (str, &(props.link_layer_protocol))) { g_printerr ("Unrecognized Link Layer Protocol '%s'\n", str); goto error_out; } diff --git a/src/qmicli/qmicli-wds.c b/src/qmicli/qmicli-wds.c index 1d8cb676..d6d82fbe 100644 --- a/src/qmicli/qmicli-wds.c +++ b/src/qmicli/qmicli-wds.c @@ -2253,7 +2253,7 @@ set_autoconnect_settings_input_create (const gchar *str) } g_strstrip (split[0]); - if (!qmicli_read_autoconnect_setting_from_string (split[0], &status)) { + if (!qmicli_read_wds_autoconnect_setting_from_string (split[0], &status)) { g_printerr ("error: failed to parse autoconnect setting\n"); goto error_out; } @@ -2265,7 +2265,7 @@ set_autoconnect_settings_input_create (const gchar *str) if (g_strv_length (split) == 2) { g_strstrip (split[1]); - if (!qmicli_read_autoconnect_setting_roaming_from_string (g_str_equal (split[1], "roaming-allowed") ? "allowed" : split[1], &roaming)) { + if (!qmicli_read_wds_autoconnect_setting_roaming_from_string (g_str_equal (split[1], "roaming-allowed") ? "allowed" : split[1], &roaming)) { g_printerr ("error: failed to parse autoconnect roaming setting\n"); goto error_out; } diff --git a/src/qmicli/qmicli.c b/src/qmicli/qmicli.c index e709ebd7..146fe284 100644 --- a/src/qmicli/qmicli.c +++ b/src/qmicli/qmicli.c @@ -531,7 +531,7 @@ device_set_expected_data_format_cb (QmiDevice *dev) QmiDeviceExpectedDataFormat expected; GError *error = NULL; - if (!qmicli_read_expected_data_format_from_string (set_expected_data_format_str, &expected) || + if (!qmicli_read_device_expected_data_format_from_string (set_expected_data_format_str, &expected) || expected == QMI_DEVICE_EXPECTED_DATA_FORMAT_UNKNOWN) g_printerr ("error: invalid requested data format: %s", set_expected_data_format_str); else if (!qmi_device_set_expected_data_format (dev, expected, &error)) { |