base-modem: define new helper MMBaseModemAtCommandAlloc

It has the same exact format as MMBaseModemAtCommand, but its contents
are assumed heap allocated.

The only real purpose of this type is to allow defining static
constant MMBaseModemAtCommand variables without warnings when using
-Wdiscarded-qualifiers.
This commit is contained in:
Aleksander Morgado
2020-01-31 10:36:50 +01:00
parent f77deb75a5
commit accd1a5841
12 changed files with 112 additions and 86 deletions

View File

@@ -883,9 +883,9 @@ response_processor_no_result_stop_on_error (MMBaseModem *self,
}
static const MMBaseModemAtCommand unsolicited_events_enable_sequence[] = {
{ (gchar *) "%STATCM=1", 10, FALSE, response_processor_no_result_stop_on_error },
{ (gchar *) "%NOTIFYEV=\"SIMREFRESH\",1", 10, FALSE, NULL },
{ (gchar *) "%PCOINFO=1", 10, FALSE, NULL },
{ "%STATCM=1", 10, FALSE, response_processor_no_result_stop_on_error },
{ "%NOTIFYEV=\"SIMREFRESH\",1", 10, FALSE, NULL },
{ "%PCOINFO=1", 10, FALSE, NULL },
{ NULL }
};
@@ -955,9 +955,9 @@ modem_3gpp_enable_unsolicited_events (MMIfaceModem3gpp *self,
/* Disabling unsolicited events (3GPP interface) */
static const MMBaseModemAtCommand unsolicited_events_disable_sequence[] = {
{ (gchar *) "%STATCM=0", 10, FALSE, NULL },
{ (gchar *) "%NOTIFYEV=\"SIMREFRESH\",0", 10, FALSE, NULL },
{ (gchar *) "%PCOINFO=0", 10, FALSE, NULL },
{ "%STATCM=0", 10, FALSE, NULL },
{ "%NOTIFYEV=\"SIMREFRESH\",0", 10, FALSE, NULL },
{ "%PCOINFO=0", 10, FALSE, NULL },
{ NULL }
};

View File

@@ -2013,8 +2013,8 @@ own_enable_unsolicited_events_ready (MMBaseModem *self,
static const MMBaseModemAtCommand unsolicited_enable_sequence[] = {
/* With ^PORTSEL we specify whether we want the PCUI port (0) or the
* modem port (1) to receive the unsolicited messages */
{ (gchar *) "^PORTSEL=0", 5, FALSE, NULL },
{ (gchar *) "^CURC=1", 3, FALSE, NULL },
{ "^PORTSEL=0", 5, FALSE, NULL },
{ "^CURC=1", 3, FALSE, NULL },
{ NULL }
};
@@ -3363,7 +3363,7 @@ own_voice_enable_unsolicited_events_ready (MMBaseModem *self,
static const MMBaseModemAtCommand unsolicited_voice_enable_sequence[] = {
/* With ^DDTMFCFG we active the DTMF Decoder */
{ (gchar *) "^DDTMFCFG=0,1", 3, FALSE, NULL },
{ "^DDTMFCFG=0,1", 3, FALSE, NULL },
{ NULL }
};
@@ -3436,7 +3436,7 @@ own_voice_disable_unsolicited_events_ready (MMBaseModem *self,
static const MMBaseModemAtCommand unsolicited_voice_disable_sequence[] = {
/* With ^DDTMFCFG we deactivate the DTMF Decoder */
{ (gchar *) "^DDTMFCFG=1,0", 3, FALSE, NULL },
{ "^DDTMFCFG=1,0", 3, FALSE, NULL },
{ NULL }
};
@@ -4187,8 +4187,8 @@ modem_check_time_reply (MMBaseModem *_self,
}
static const MMBaseModemAtCommand time_cmd_sequence[] = {
{ (gchar *) "^NTCT?", 3, FALSE, modem_check_time_reply }, /* 3GPP/LTE */
{ (gchar *) "^TIME", 3, FALSE, modem_check_time_reply }, /* CDMA */
{ "^NTCT?", 3, FALSE, modem_check_time_reply }, /* 3GPP/LTE */
{ "^TIME", 3, FALSE, modem_check_time_reply }, /* CDMA */
{ NULL }
};

View File

@@ -1161,7 +1161,7 @@ parse_bands (const gchar *response, guint32 *out_len)
/* Load supported bands (Modem interface) */
typedef struct {
MMBaseModemAtCommand *cmds;
MMBaseModemAtCommandAlloc *cmds;
GSList *check_bands;
GSList *enabled_bands;
guint32 idx;
@@ -1173,7 +1173,7 @@ supported_bands_context_free (SupportedBandsContext *ctx)
guint i;
for (i = 0; ctx->cmds[i].command; i++)
g_free (ctx->cmds[i].command);
mm_base_modem_at_command_alloc_clear (&ctx->cmds[i]);
g_free (ctx->cmds);
g_slist_free_full (ctx->check_bands, (GDestroyNotify) band_free);
g_slist_free_full (ctx->enabled_bands, (GDestroyNotify) band_free);
@@ -1272,7 +1272,7 @@ load_supported_bands_get_current_bands_ready (MMIfaceModem *self,
* to its current enabled/disabled state.
*/
iter = ctx->check_bands = parse_bands (response, &len);
ctx->cmds = g_new0 (MMBaseModemAtCommand, len + 1);
ctx->cmds = g_new0 (MMBaseModemAtCommandAlloc, len + 1);
while (iter) {
Band *b = iter->data;
@@ -1296,7 +1296,7 @@ load_supported_bands_get_current_bands_ready (MMIfaceModem *self,
}
mm_base_modem_at_sequence (MM_BASE_MODEM (self),
ctx->cmds,
(const MMBaseModemAtCommand *)ctx->cmds,
ctx,
(GDestroyNotify) supported_bands_context_free,
(GAsyncReadyCallback) load_supported_bands_ready,

View File

@@ -406,9 +406,9 @@ enabling_init_sequence_ready (MMBaseModem *self,
static const MMBaseModemAtCommand enabling_modem_init_sequence[] = {
/* Init command */
{ (gchar *) "&F", 3, FALSE, NULL },
{ "&F", 3, FALSE, NULL },
/* Ensure disconnected */
{ (gchar *) "*ENAP=0", 3, FALSE, NULL },
{ "*ENAP=0", 3, FALSE, NULL },
{ NULL }
};
@@ -614,18 +614,18 @@ factory_reset_finish (MMIfaceModem *self,
static const MMBaseModemAtCommand factory_reset_sequence[] = {
/* Init command */
{ (gchar *) "&F +CMEE=0", 3, FALSE, NULL },
{ (gchar *) "+COPS=0", 3, FALSE, NULL },
{ (gchar *) "+CR=0", 3, FALSE, NULL },
{ (gchar *) "+CRC=0", 3, FALSE, NULL },
{ (gchar *) "+CREG=0", 3, FALSE, NULL },
{ (gchar *) "+CMER=0", 3, FALSE, NULL },
{ (gchar *) "*EPEE=0", 3, FALSE, NULL },
{ (gchar *) "+CNMI=2, 0, 0, 0, 0", 3, FALSE, NULL },
{ (gchar *) "+CGREG=0", 3, FALSE, NULL },
{ (gchar *) "*EIAD=0", 3, FALSE, NULL },
{ (gchar *) "+CGSMS=3", 3, FALSE, NULL },
{ (gchar *) "+CSCA=\"\",129", 3, FALSE, NULL },
{ "&F +CMEE=0", 3, FALSE, NULL },
{ "+COPS=0", 3, FALSE, NULL },
{ "+CR=0", 3, FALSE, NULL },
{ "+CRC=0", 3, FALSE, NULL },
{ "+CREG=0", 3, FALSE, NULL },
{ "+CMER=0", 3, FALSE, NULL },
{ "*EPEE=0", 3, FALSE, NULL },
{ "+CNMI=2, 0, 0, 0, 0", 3, FALSE, NULL },
{ "+CGREG=0", 3, FALSE, NULL },
{ "*EIAD=0", 3, FALSE, NULL },
{ "+CGSMS=3", 3, FALSE, NULL },
{ "+CSCA=\"\",129", 3, FALSE, NULL },
{ NULL }
};
@@ -943,8 +943,8 @@ own_enable_unsolicited_events_ready (MMBaseModem *self,
}
static const MMBaseModemAtCommand unsolicited_enable_sequence[] = {
{ (gchar *) "*ERINFO=1", 5, FALSE, NULL },
{ (gchar *) "*E2NAP=1", 5, FALSE, NULL },
{ "*ERINFO=1", 5, FALSE, NULL },
{ "*E2NAP=1", 5, FALSE, NULL },
{ NULL }
};
@@ -1033,8 +1033,8 @@ own_disable_unsolicited_events_ready (MMBaseModem *self,
}
static const MMBaseModemAtCommand unsolicited_disable_sequence[] = {
{ (gchar *) "*ERINFO=0", 5, FALSE, NULL },
{ (gchar *) "*E2NAP=0", 5, FALSE, NULL },
{ "*ERINFO=0", 5, FALSE, NULL },
{ "*E2NAP=0", 5, FALSE, NULL },
{ NULL }
};

View File

@@ -724,13 +724,13 @@ modem_3gpp_cleanup_unsolicited_events (MMIfaceModem3gpp *self,
static const MMBaseModemAtCommand unsolicited_enable_sequence[] = {
/* enable signal URC */
{ (gchar *) "+ECSQ=2", 5, FALSE, NULL },
{ "+ECSQ=2", 5, FALSE, NULL },
{ NULL }
};
static const MMBaseModemAtCommand unsolicited_disable_sequence[] = {
/* disable signal URC */
{ (gchar *) "+ECSQ=0" , 5, FALSE, NULL },
{ "+ECSQ=0" , 5, FALSE, NULL },
{ NULL }
};

View File

@@ -246,8 +246,8 @@ response_processor_nwmdn_ignore_at_errors (MMBaseModem *self,
}
static const MMBaseModemAtCommand own_numbers_commands[] = {
{ (gchar *) "+CNUM", 3, TRUE, response_processor_cnum_ignore_at_errors },
{ (gchar *) "$NWMDN", 3, TRUE, response_processor_nwmdn_ignore_at_errors },
{ "+CNUM", 3, TRUE, response_processor_cnum_ignore_at_errors },
{ "$NWMDN", 3, TRUE, response_processor_nwmdn_ignore_at_errors },
{ NULL }
};

View File

@@ -975,10 +975,10 @@ own_enable_unsolicited_events_ready (MMBaseModem *self,
}
static const MMBaseModemAtCommand unsolicited_enable_sequence[] = {
{ (gchar *) "_OSSYS=1", 3, FALSE, NULL },
{ (gchar *) "_OCTI=1", 3, FALSE, NULL },
{ (gchar *) "_OUWCTI=1", 3, FALSE, NULL },
{ (gchar *) "_OSQI=1", 3, FALSE, NULL },
{ "_OSSYS=1", 3, FALSE, NULL },
{ "_OCTI=1", 3, FALSE, NULL },
{ "_OUWCTI=1", 3, FALSE, NULL },
{ "_OSQI=1", 3, FALSE, NULL },
{ NULL }
};
@@ -1030,10 +1030,10 @@ modem_3gpp_disable_unsolicited_events_finish (MMIfaceModem3gpp *self,
}
static const MMBaseModemAtCommand unsolicited_disable_sequence[] = {
{ (gchar *) "_OSSYS=0", 3, FALSE, NULL },
{ (gchar *) "_OCTI=0", 3, FALSE, NULL },
{ (gchar *) "_OUWCTI=0", 3, FALSE, NULL },
{ (gchar *) "_OSQI=0", 3, FALSE, NULL },
{ "_OSSYS=0", 3, FALSE, NULL },
{ "_OCTI=0", 3, FALSE, NULL },
{ "_OUWCTI=0", 3, FALSE, NULL },
{ "_OSQI=0", 3, FALSE, NULL },
{ NULL }
};

View File

@@ -1805,8 +1805,8 @@ parse_time_reply (MMBaseModem *self,
}
static const MMBaseModemAtCommand time_check_sequence[] = {
{ (gchar *) "!TIME?", 3, FALSE, parse_time_reply }, /* 3GPP */
{ (gchar *) "!SYSTIME?", 3, FALSE, parse_time_reply }, /* CDMA */
{ "!TIME?", 3, FALSE, parse_time_reply }, /* 3GPP */
{ "!SYSTIME?", 3, FALSE, parse_time_reply }, /* CDMA */
{ NULL }
};

View File

@@ -1184,8 +1184,8 @@ response_processor_service_ignore_at_errors (MMBaseModem *self,
}
static const MMBaseModemAtCommand access_tech_commands[] = {
{ (gchar *) "#PSNT?", 3, FALSE, response_processor_psnt_ignore_at_errors },
{ (gchar *) "+SERVICE?", 3, FALSE, response_processor_service_ignore_at_errors },
{ "#PSNT?", 3, FALSE, response_processor_psnt_ignore_at_errors },
{ "+SERVICE?", 3, FALSE, response_processor_service_ignore_at_errors },
{ NULL }
};

View File

@@ -616,3 +616,9 @@ mm_base_modem_at_command_raw (MMBaseModem *self,
{
_at_command (self, command, timeout, allow_cached, TRUE, callback, user_data);
}
void
mm_base_modem_at_command_alloc_clear (MMBaseModemAtCommandAlloc *command)
{
g_free (command->command);
}

View File

@@ -51,10 +51,10 @@ typedef gboolean (* MMBaseModemAtResponseProcessor) (MMBaseModem *self,
GVariant **result,
GError **result_error);
/* Struct to configure AT command operations */
/* Struct to configure AT command operations (constant) */
typedef struct {
/* The AT command */
gchar *command;
const gchar *command;
/* Timeout of the command, in seconds */
guint timeout;
/* Flag to allow cached replies */
@@ -164,4 +164,24 @@ const gchar *mm_base_modem_at_command_full_finish (MMBaseModem *self,
GAsyncResult *res,
GError **error);
/******************************************************************************/
/* Support for MMBaseModemAtCommand with heap allocated contents */
/* Exactly same format as MMBaseModemAtCommand, just without
* a constant command string. */
typedef struct {
gchar *command;
guint timeout;
gboolean allow_cached;
MMBaseModemAtResponseProcessor response_processor;
} MMBaseModemAtCommandAlloc;
G_STATIC_ASSERT (sizeof (MMBaseModemAtCommandAlloc) == sizeof (MMBaseModemAtCommand));
G_STATIC_ASSERT (G_STRUCT_OFFSET (MMBaseModemAtCommandAlloc, command) == G_STRUCT_OFFSET (MMBaseModemAtCommand, command));
G_STATIC_ASSERT (G_STRUCT_OFFSET (MMBaseModemAtCommandAlloc, timeout) == G_STRUCT_OFFSET (MMBaseModemAtCommand, timeout));
G_STATIC_ASSERT (G_STRUCT_OFFSET (MMBaseModemAtCommandAlloc, allow_cached) == G_STRUCT_OFFSET (MMBaseModemAtCommand, allow_cached));
G_STATIC_ASSERT (G_STRUCT_OFFSET (MMBaseModemAtCommandAlloc, response_processor) == G_STRUCT_OFFSET (MMBaseModemAtCommand, response_processor));
void mm_base_modem_at_command_alloc_clear (MMBaseModemAtCommandAlloc *command);
#endif /* MM_BASE_MODEM_AT_H */

View File

@@ -675,10 +675,10 @@ parse_caps_cgmm (MMBaseModem *self,
}
static const MMBaseModemAtCommand capabilities[] = {
{ (gchar *)"+GCAP", 2, TRUE, parse_caps_gcap },
{ (gchar *)"I", 1, TRUE, parse_caps_gcap }, /* yes, really parse as +GCAP */
{ (gchar *)"+CPIN?", 1, FALSE, parse_caps_cpin },
{ (gchar *)"+CGMM", 1, TRUE, parse_caps_cgmm },
{ "+GCAP", 2, TRUE, parse_caps_gcap },
{ "I", 1, TRUE, parse_caps_gcap }, /* yes, really parse as +GCAP */
{ "+CPIN?", 1, FALSE, parse_caps_cpin },
{ "+CGMM", 1, TRUE, parse_caps_cgmm },
{ NULL }
};
@@ -926,8 +926,8 @@ modem_load_manufacturer_finish (MMIfaceModem *self,
}
static const MMBaseModemAtCommand manufacturers[] = {
{ (gchar *)"+CGMI", 3, TRUE, response_processor_string_ignore_at_errors },
{ (gchar *)"+GMI", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+CGMI", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+GMI", 3, TRUE, response_processor_string_ignore_at_errors },
{ NULL }
};
@@ -966,8 +966,8 @@ modem_load_model_finish (MMIfaceModem *self,
}
static const MMBaseModemAtCommand models[] = {
{ (gchar *)"+CGMM", 3, TRUE, response_processor_string_ignore_at_errors },
{ (gchar *)"+GMM", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+CGMM", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+GMM", 3, TRUE, response_processor_string_ignore_at_errors },
{ NULL }
};
@@ -1006,8 +1006,8 @@ modem_load_revision_finish (MMIfaceModem *self,
}
static const MMBaseModemAtCommand revisions[] = {
{ (gchar *)"+CGMR", 3, TRUE, response_processor_string_ignore_at_errors },
{ (gchar *)"+GMR", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+CGMR", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+GMR", 3, TRUE, response_processor_string_ignore_at_errors },
{ NULL }
};
@@ -1066,8 +1066,8 @@ modem_load_equipment_identifier_finish (MMIfaceModem *self,
}
static const MMBaseModemAtCommand equipment_identifiers[] = {
{ (gchar *)"+CGSN", 3, TRUE, response_processor_string_ignore_at_errors },
{ (gchar *)"+GSN", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+CGSN", 3, TRUE, response_processor_string_ignore_at_errors },
{ "+GSN", 3, TRUE, response_processor_string_ignore_at_errors },
{ NULL }
};
@@ -1156,8 +1156,8 @@ parse_ati_reply (MMBaseModem *self,
}
static const MMBaseModemAtCommand device_identifier_steps[] = {
{ (gchar *)"ATI", 3, TRUE, (MMBaseModemAtResponseProcessor)parse_ati_reply },
{ (gchar *)"ATI1", 3, TRUE, (MMBaseModemAtResponseProcessor)parse_ati_reply },
{ "ATI", 3, TRUE, (MMBaseModemAtResponseProcessor)parse_ati_reply },
{ "ATI1", 3, TRUE, (MMBaseModemAtResponseProcessor)parse_ati_reply },
{ NULL }
};
@@ -2083,8 +2083,8 @@ signal_quality_csq_ready (MMBroadbandModem *self,
* try the other command if the first one fails.
*/
static const MMBaseModemAtCommand signal_quality_csq_sequence[] = {
{ (gchar *)"+CSQ", 3, FALSE, response_processor_string_ignore_at_errors },
{ (gchar *)"+CSQ?", 3, FALSE, response_processor_string_ignore_at_errors },
{ "+CSQ", 3, FALSE, response_processor_string_ignore_at_errors },
{ "+CSQ?", 3, FALSE, response_processor_string_ignore_at_errors },
{ NULL }
};
@@ -3600,14 +3600,14 @@ typedef struct {
* First one with quotes
* Second without.
* + last NUL */
MMBaseModemAtCommand charset_commands[3];
MMBaseModemAtCommandAlloc charset_commands[3];
} SetupCharsetContext;
static void
setup_charset_context_free (SetupCharsetContext *ctx)
{
g_free (ctx->charset_commands[0].command);
g_free (ctx->charset_commands[1].command);
mm_base_modem_at_command_alloc_clear (&ctx->charset_commands[0]);
mm_base_modem_at_command_alloc_clear (&ctx->charset_commands[1]);
g_free (ctx);
}
@@ -3735,7 +3735,7 @@ modem_setup_charset (MMIfaceModem *self,
/* Launch sequence */
mm_base_modem_at_sequence (
MM_BASE_MODEM (self),
ctx->charset_commands,
(const MMBaseModemAtCommand *)ctx->charset_commands,
NULL, /* response_processor_context */
NULL, /* response_processor_context_free */
(GAsyncReadyCallback)charset_change_ready,
@@ -5235,43 +5235,43 @@ parse_registration_setup_reply (MMBaseModem *self,
static const MMBaseModemAtCommand cs_registration_sequence[] = {
/* Enable unsolicited registration notifications in CS network, with location */
{ (gchar *)"+CREG=2", 3, FALSE, parse_registration_setup_reply },
{ "+CREG=2", 3, FALSE, parse_registration_setup_reply },
/* Enable unsolicited registration notifications in CS network, without location */
{ (gchar *)"+CREG=1", 3, FALSE, parse_registration_setup_reply },
{ "+CREG=1", 3, FALSE, parse_registration_setup_reply },
{ NULL }
};
static const MMBaseModemAtCommand cs_unregistration_sequence[] = {
/* Disable unsolicited registration notifications in CS network */
{ (gchar *)"+CREG=0", 3, FALSE, parse_registration_setup_reply },
{ "+CREG=0", 3, FALSE, parse_registration_setup_reply },
{ NULL }
};
static const MMBaseModemAtCommand ps_registration_sequence[] = {
/* Enable unsolicited registration notifications in PS network, with location */
{ (gchar *)"+CGREG=2", 3, FALSE, parse_registration_setup_reply },
{ "+CGREG=2", 3, FALSE, parse_registration_setup_reply },
/* Enable unsolicited registration notifications in PS network, without location */
{ (gchar *)"+CGREG=1", 3, FALSE, parse_registration_setup_reply },
{ "+CGREG=1", 3, FALSE, parse_registration_setup_reply },
{ NULL }
};
static const MMBaseModemAtCommand ps_unregistration_sequence[] = {
/* Disable unsolicited registration notifications in PS network */
{ (gchar *)"+CGREG=0", 3, FALSE, parse_registration_setup_reply },
{ "+CGREG=0", 3, FALSE, parse_registration_setup_reply },
{ NULL }
};
static const MMBaseModemAtCommand eps_registration_sequence[] = {
/* Enable unsolicited registration notifications in EPS network, with location */
{ (gchar *)"+CEREG=2", 3, FALSE, parse_registration_setup_reply },
{ "+CEREG=2", 3, FALSE, parse_registration_setup_reply },
/* Enable unsolicited registration notifications in EPS network, without location */
{ (gchar *)"+CEREG=1", 3, FALSE, parse_registration_setup_reply },
{ "+CEREG=1", 3, FALSE, parse_registration_setup_reply },
{ NULL }
};
static const MMBaseModemAtCommand eps_unregistration_sequence[] = {
/* Disable unsolicited registration notifications in PS network */
{ (gchar *)"+CEREG=0", 3, FALSE, parse_registration_setup_reply },
{ "+CEREG=0", 3, FALSE, parse_registration_setup_reply },
{ NULL }
};
@@ -7039,16 +7039,16 @@ cnmi_response_processor (MMBaseModem *self,
}
static const MMBaseModemAtCommand cnmi_sequence[] = {
{ (gchar *)"+CNMI=2,1,2,1,0", 3, FALSE, cnmi_response_processor },
{ "+CNMI=2,1,2,1,0", 3, FALSE, cnmi_response_processor },
/* Many Qualcomm-based devices don't support <ds> of '1', despite
* reporting they support it in the +CNMI=? response. But they do
* accept '2'.
*/
{ (gchar *)"+CNMI=2,1,2,2,0", 3, FALSE, cnmi_response_processor },
{ "+CNMI=2,1,2,2,0", 3, FALSE, cnmi_response_processor },
/* Last resort: turn off delivery status reports altogether */
{ (gchar *)"+CNMI=2,1,2,0,0", 3, FALSE, cnmi_response_processor },
{ "+CNMI=2,1,2,0,0", 3, FALSE, cnmi_response_processor },
{ NULL }
};
@@ -9881,8 +9881,8 @@ modem_time_load_network_timezone (MMIfaceModemTime *self,
/* Check support (Time interface) */
static const MMBaseModemAtCommand time_check_sequence[] = {
{ (gchar *)"+CTZU=1", 3, TRUE, mm_base_modem_response_processor_no_result_continue },
{ (gchar *)"+CCLK?", 3, TRUE, mm_base_modem_response_processor_string },
{ "+CTZU=1", 3, TRUE, mm_base_modem_response_processor_no_result_continue },
{ "+CCLK?", 3, TRUE, mm_base_modem_response_processor_string },
{ NULL }
};