simutil: Convert eons APIs to use ell
PATCH v2 1/14 simutil: Convert eons APIs to use ell
While here, also remove sim_eons_optimize() as it is no longer needed. The ell queue implementation natively supports pushing to the back of a linked list. Also tighten up some length checks and make 'length' arguments unsigned.
--- src/network.c | 2 - src/simutil.c | 116 +++++++++++++++++++++----------------------- src/simutil.h | 15 +++--- unit/test-simutil.c | 1 - 4 files changed, 63 insertions(+), 71 deletions(-)
src/network.c +0 -2
@@ -1581,8 +1581,6 @@ static void sim_opl_read_cb(int ok, int length, int record,return ; optimize: -sim_eons_optimize (netreg->eons); -for (l = netreg->operator_list; l; l = l->next) {struct network_operator_data *opd = l->data;const struct sim_eons_operator_info *eons_info;
src/simutil.c +55 -61
202 lines not on this page · raw message
src/simutil.h +8 -7
@@ -20,6 +20,7 @@*/ #include <stdbool.h> +#include <stdint.h> #define SIM_EFSPN_DC_HOME_PLMN_BIT 0x1#define SIM_EFSPN_DC_ROAMING_SPN_BIT 0x2
@@ -299,9 +300,9 @@ enum ber_tlv_data_encoding_type {struct sim_eons_operator_info {char *longname; -gboolean long_ci; +bool long_ci;char *shortname; -gboolean short_ci; +bool short_ci;char *info; };
@@ -460,18 +461,18 @@ gboolean ber_tlv_builder_recurse_comprehension(struct ber_tlv_builder *builder,void ber_tlv_builder_optimize (struct ber_tlv_builder *builder,unsigned char **pdu,unsigned int *len); -struct sim_eons *sim_eons_new (int pnn_records); -void sim_eons_add_pnn_record (struct sim_eons *eons,int record, -const guint8 *tlv,int length); +struct sim_eons *sim_eons_new (uint32_t pnn_records); +void sim_eons_add_pnn_record (struct sim_eons *eons,uint32_t record, +const uint8_t *tlv,uint16_t length);gboolean sim_eons_pnn_is_empty (struct sim_eons *eons);void sim_eons_add_opl_record (struct sim_eons *eons, -const guint8 *contents,int length); +const uint8_t *contents,uint16_t length);void sim_eons_optimize (struct sim_eons *eons);const struct sim_eons_operator_info *sim_eons_lookup_with_lac (struct sim_eons *eons,const char *mcc,const char *mnc, -guint16 lac); +uint16_t lac);const struct sim_eons_operator_info *sim_eons_lookup (struct sim_eons *eons,const char *mcc,const char *mnc);
unit/test-simutil.c +0 -1
@@ -393,7 +393,6 @@ static void test_eons(void)g_assert (!sim_eons_pnn_is_empty (eons_info));sim_eons_add_opl_record (eons_info, valid_efopl,sizeof (valid_efopl)); -sim_eons_optimize (eons_info); op_info =sim_eons_lookup (eons_info,"246" ,"82" );g_assert (op_info ==NULL );
Signature · 1 line
2.43.0
PATCH v2 2/14 sim: Simplify SPN management logic
The current implementation kicks off reading of the SPN only if an spn watch has been registered. This made sense at the time since the only atoms that used spn were netreg and gprs. Typically they were initialized in the post_online state, which in effect delayed SPN reading until that time.
With the introduction of provisioning inside the LTE atom, the spn watch is always registered for LTE modems (nearly all modems now and going forward). Simplify the SPN reading logic by reading it once the sim has been initialized by kicking off the read procedure inside sim_ready().
While here, remove tracking of cphs_spn_watch, ef_spn_watch and cphs_spn_short_watch. All sim file watches are automatically destroyed once the ofono_sim_context is destroyed.
--- src/sim.c | 353 +++++++++++++++++++++++------------------------------- 1 file changed, 153 insertions(+), 200 deletions(-)
src/sim.c +153 -200
@@ -113,9 +113,6 @@ struct ofono_sim {char *spn;char *spn_dc;struct ofono_watchlist *spn_watches; -unsigned int ef_spn_watch; -unsigned int cphs_spn_watch; -unsigned int cphs_spn_short_watch;struct sim_fs *simfs;struct sim_fs *simfs_isim;
@@ -139,13 +136,13 @@ struct ofono_sim {GSList *aid_sessions;GSList *aid_list;char *impi; - bool reading_spn : 1; bool language_prefs_update : 1; bool fixed_dialing : 1; bool barred_dialing : 1; bool sdn_ready : 1; bool initialized : 1; bool wait_initialized : 1; + bool spn_initialized : 1; };struct cached_pin {
@@ -1532,6 +1529,137 @@ static void sim_own_numbers_changed(int id, void *userdata)sim_own_numbers_update (sim); } +static void spn_watch_cb (gpointer data,gpointer user_data) +{ +struct ofono_watchlist_item *item = data; +struct ofono_sim *sim = user_data; + +if (item->notify) + ((ofono_sim_spn_cb_t ) item->notify)(sim->spn, sim->spn_dc, + item->notify_data); +} + +static void sim_spn_set (struct ofono_sim *sim,const void *data,int length, +const unsigned char *dc) +{ +DBusConnection *conn =ofono_dbus_get_connection (); +const char *path =__ofono_atom_get_path (sim->atom); + +l_free (sim->spn); + sim->spn =NULL ; + +l_free (sim->spn_dc); + sim->spn_dc =NULL ; + +if (data ==NULL ) + goto notify; + +/* +* TS 31.102 says: +* +* the string shall use: +* +* - either the SMS default 7-bit coded alphabet as defined in +* TS 23.038 [5] with bit 8 set to 0. The string shall be left +* justified. Unused bytes shall be set to 'FF'. +* +* - or one of the UCS2 code options defined in the annex of TS +* 31.101 [11]. +* +* 31.101 has no such annex though. 51.101 refers to Annex B of +* itself which is not there either. 11.11 contains the same +* paragraph as 51.101 and has an Annex B which we implement. +*/ + sim->spn =sim_string_to_utf8 (data, length); +if (sim->spn ==NULL ) { +ofono_error ("EFspn read successfully, but couldn't parse" ); + goto notify; + } + +if (strlen (sim->spn) ==0 ) { +l_free (sim->spn); + sim->spn =NULL ; + goto notify; + } + +if (dc) + sim->spn_dc =l_memdup (dc,1 ); + +notify: + sim->spn_initialized = true; + +if (sim->spn) +ofono_dbus_signal_property_changed (conn, path, +OFONO_SIM_MANAGER_INTERFACE , +"ServiceProviderName" , +DBUS_TYPE_STRING , &sim->spn); + +g_slist_foreach (sim->spn_watches->items, spn_watch_cb, sim); +} + +static void sim_cphs_spn_short_read_cb (int ok,int length,int record, +const unsigned char *data, +int record_length,void *user_data) +{ +struct ofono_sim *sim = user_data; + +if (!ok) { +sim_spn_set (sim,NULL ,0 ,NULL ); +return ; + } + +sim_spn_set (sim, data, length,NULL ); +} + +static void sim_cphs_spn_read_cb (int ok,int length,int record, +const unsigned char *data, +int record_length,void *user_data) +{ +struct ofono_sim *sim = user_data; + +if (!ok) { +if (__ofono_sim_cphs_service_available (sim, +SIM_CPHS_SERVICE_SHORT_SPN )) +ofono_sim_read (sim->context, +SIM_EF_CPHS_SPN_SHORT_FILEID , +OFONO_SIM_FILE_STRUCTURE_TRANSPARENT , + sim_cphs_spn_short_read_cb, sim); +else +sim_spn_set (sim,NULL ,0 ,NULL ); + +return ; + } + +sim_spn_set (sim, data, length,NULL ); +} + +static void sim_spn_read_cb (int ok,int length,int record, +const unsigned char *data, +int record_length,void *user_data) +{ +struct ofono_sim *sim = user_data; + +if (!ok) { +ofono_sim_read (sim->context,SIM_EF_CPHS_SPN_FILEID , +OFONO_SIM_FILE_STRUCTURE_TRANSPARENT , + sim_cphs_spn_read_cb, sim); + +return ; + } + +sim_spn_set (sim, data +1 , length -1 , data); +} + +static void sim_spn_changed (int id,void *userdata) +{ +struct ofono_sim *sim = userdata; + + sim->spn_initialized = false; +ofono_sim_read (sim->context,SIM_EFSPN_FILEID , +OFONO_SIM_FILE_STRUCTURE_TRANSPARENT , + sim_spn_read_cb, sim); +} +static void sim_efimg_read_cb (int ok,int length,int record,const unsigned char *data,int record_length,void *userdata)
@@ -1622,6 +1750,18 @@ static void sim_ready(enum ofono_sim_state new_state, void *user)ofono_sim_add_file_watch (sim->context,SIM_EFSDN_FILEID , sim_service_numbers_changed, sim,NULL ); +/* Service Provider Name (EFspn and CPHS equivalents) */ +sim_spn_changed (SIM_EFSPN_FILEID , sim); +ofono_sim_add_file_watch (sim->context,SIM_EFSPN_FILEID , + sim_spn_changed, sim,NULL ); +ofono_sim_add_file_watch (sim->context,SIM_EF_CPHS_SPN_FILEID , + sim_spn_changed, sim,NULL ); + +if (__ofono_sim_cphs_service_available (sim,SIM_CPHS_SERVICE_SHORT_SPN )) +ofono_sim_add_file_watch (sim->context, +SIM_EF_CPHS_SPN_SHORT_FILEID , + sim_spn_changed, sim,NULL ); +ofono_sim_read (sim->context,SIM_EFIMG_FILEID ,OFONO_SIM_FILE_STRUCTURE_FIXED , sim_efimg_read_cb, sim); ofono_sim_add_file_watch(sim->context, SIM_EFIMG_FILEID,
@@ -2611,37 +2751,6 @@ static void sim_free_early_state(struct ofono_sim *sim) } } -static void sim_spn_close (struct ofono_sim *sim) -{ -/* -* We have not initialized SPN logic at all yet, either because -* no netreg / gprs atom has been needed or we have not reached the -* post_sim state -*/ -if (sim->ef_spn_watch ==0 ) -return ; - -ofono_sim_remove_file_watch (sim->context, sim->ef_spn_watch); - sim->ef_spn_watch =0 ; - -ofono_sim_remove_file_watch (sim->context, sim->cphs_spn_watch); - sim->cphs_spn_watch =0 ; - -if (sim->cphs_spn_short_watch) { -ofono_sim_remove_file_watch (sim->context, - sim->cphs_spn_short_watch); - sim->cphs_spn_short_watch =0 ; - } - - sim->reading_spn = false; - -l_free (sim->spn); - sim->spn =NULL ; - -l_free (sim->spn_dc); - sim->spn_dc =NULL ; -} -static void aid_session_free (gpointer data) {struct ofono_sim_aid_session *session = data;
@@ -2709,7 +2818,14 @@ static void sim_free_main_state(struct ofono_sim *sim) sim->fixed_dialing = false; sim->barred_dialing = false; -sim_spn_close (sim); +/* Service Provider Name related */ + sim->spn_initialized = false; + +l_free (sim->spn); + sim->spn =NULL ; + +l_free (sim->spn_dc); + sim->spn_dc =NULL ;if (sim->context) {ofono_sim_context_free (sim->context);
@@ -2929,163 +3045,6 @@ enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim)return sim->state; } -static void spn_watch_cb (gpointer data,gpointer user_data) -{ -struct ofono_watchlist_item *item = data; -struct ofono_sim *sim = user_data; - -if (item->notify) - ((ofono_sim_spn_cb_t ) item->notify)(sim->spn, sim->spn_dc, - item->notify_data); -} - -static inline void spn_watches_notify (struct ofono_sim *sim) -{ -if (sim->spn_watches->items) -g_slist_foreach (sim->spn_watches->items, spn_watch_cb, sim); - - sim->reading_spn = false; -} - -static void sim_spn_set (struct ofono_sim *sim,const void *data,int length, -const unsigned char *dc) -{ -DBusConnection *conn =ofono_dbus_get_connection (); -const char *path =__ofono_atom_get_path (sim->atom); - -l_free (sim->spn); - sim->spn =NULL ; - -l_free (sim->spn_dc); - sim->spn_dc =NULL ; - -if (data ==NULL ) - goto notify; - -/* -* TS 31.102 says: -* -* the string shall use: -* -* - either the SMS default 7-bit coded alphabet as defined in -* TS 23.038 [5] with bit 8 set to 0. The string shall be left -* justified. Unused bytes shall be set to 'FF'. -* -* - or one of the UCS2 code options defined in the annex of TS -* 31.101 [11]. -* -* 31.101 has no such annex though. 51.101 refers to Annex B of -* itself which is not there either. 11.11 contains the same -* paragraph as 51.101 and has an Annex B which we implement. -*/ - sim->spn =sim_string_to_utf8 (data, length); -if (sim->spn ==NULL ) { -ofono_error ("EFspn read successfully, but couldn't parse" ); - goto notify; - } - -if (strlen (sim->spn) ==0 ) { -l_free (sim->spn); - sim->spn =NULL ; - goto notify; - } - -if (dc) - sim->spn_dc =l_memdup (dc,1 ); - -notify: -if (sim->spn) -ofono_dbus_signal_property_changed (conn, path, -OFONO_SIM_MANAGER_INTERFACE , -"ServiceProviderName" , -DBUS_TYPE_STRING , &sim->spn); - -spn_watches_notify (sim); -} - -static void sim_cphs_spn_short_read_cb (int ok,int length,int record, -const unsigned char *data, -int record_length,void *user_data) -{ -struct ofono_sim *sim = user_data; - -if (!ok) { -sim_spn_set (sim,NULL ,0 ,NULL ); -return ; - } - -sim_spn_set (sim, data, length,NULL ); -} - -static void sim_cphs_spn_read_cb (int ok,int length,int record, -const unsigned char *data, -int record_length,void *user_data) -{ -struct ofono_sim *sim = user_data; - -if (!ok) { -if (__ofono_sim_cphs_service_available (sim, -SIM_CPHS_SERVICE_SHORT_SPN )) -ofono_sim_read (sim->context, -SIM_EF_CPHS_SPN_SHORT_FILEID , -OFONO_SIM_FILE_STRUCTURE_TRANSPARENT , - sim_cphs_spn_short_read_cb, sim); -else -sim_spn_set (sim,NULL ,0 ,NULL ); - -return ; - } - -sim_spn_set (sim, data, length,NULL ); -} - -static void sim_spn_read_cb (int ok,int length,int record, -const unsigned char *data, -int record_length,void *user_data) -{ -struct ofono_sim *sim = user_data; - -if (!ok) { -ofono_sim_read (sim->context,SIM_EF_CPHS_SPN_FILEID , -OFONO_SIM_FILE_STRUCTURE_TRANSPARENT , - sim_cphs_spn_read_cb, sim); - -return ; - } - -sim_spn_set (sim, data +1 , length -1 , data); -} - -static void sim_spn_changed (int id,void *userdata) -{ -struct ofono_sim *sim = userdata; - -if (sim->reading_spn) -return ; - - sim->reading_spn = true; -ofono_sim_read (sim->context,SIM_EFSPN_FILEID , -OFONO_SIM_FILE_STRUCTURE_TRANSPARENT , - sim_spn_read_cb, sim); -} - -static void sim_spn_init (struct ofono_sim *sim) -{ - sim->ef_spn_watch =ofono_sim_add_file_watch (sim->context, -SIM_EFSPN_FILEID , sim_spn_changed, sim, -NULL ); - - sim->cphs_spn_watch =ofono_sim_add_file_watch (sim->context, -SIM_EF_CPHS_SPN_FILEID , - sim_spn_changed, sim,NULL ); - -if (__ofono_sim_cphs_service_available (sim, -SIM_CPHS_SERVICE_SHORT_SPN )) - sim->cphs_spn_short_watch =ofono_sim_add_file_watch ( - sim->context,SIM_EF_CPHS_SPN_SHORT_FILEID , - sim_spn_changed, sim,NULL ); -} -ofono_bool_t ofono_sim_add_spn_watch (struct ofono_sim *sim,unsigned int *id,ofono_sim_spn_cb_t cb,void *data,ofono_destroy_func destroy)
@@ -3110,13 +3069,7 @@ ofono_bool_t ofono_sim_add_spn_watch(struct ofono_sim *sim, unsigned int *id, *id = watch_id; -if (sim->ef_spn_watch ==0 ) { -sim_spn_init (sim); -sim_spn_changed (0 , sim); -return TRUE; - } - -if (sim->reading_spn) +if (!sim->spn_initialized)return TRUE; ((ofono_sim_spn_cb_t) item->notify)(sim->spn, sim->spn_dc,
Signature · 1 line
2.43.0
PATCH v2 3/14 data: Remove AweSIM entry
In reply to Denis KenziorIt has the same MCC/MNC and APN settings as AT&T
--- data/provision.json | 24 ------------------------ 1 file changed, 24 deletions(-)
data/provision.json +0 -24
@@ -14425,30 +14425,6 @@ } ] }, - { - "name": "AweSIM", - "ids": [ - "310410" - ], - "apns": [ - { - "name": "AweSIM Internet", - "apn": "NXTGENPHONE", - "type": [ - "internet" - ] - }, - { - "name": "AweSIM MMS", - "apn": "NXTGENPHONE", - "type": [ - "mms" - ], - "mmsc": "http://mmsc.mobile.att.net", - "mmsproxy": "proxy.mobile.att.net:80" - } - ] - }, { "name": "Straight Talk", "ids": [
Signature · 1 line
2.43.0
PATCH v2 4/14 data: Mark some MVNOs via the "spn" attribute
In reply to Denis KenziorMost likely these MVNOs use GID1/GID2 or some other magic to be auto-detected properly. Mark them using the SPN tag so major US carriers can be autodetected easier.
--- data/provision.json | 5 +++++ 1 file changed, 5 insertions(+)
data/provision.json +5 -0
@@ -14372,6 +14372,7 @@ "ids": [ "310240" ], + "spn": "Ting", "apns": [ { "name": "Ting Data",
@@ -14430,6 +14431,7 @@ "ids": [ "310410" ], + "spn": "Tracfone", "apns": [ { "apn": "att.mvno",
@@ -14450,6 +14452,7 @@ "ids": [ "310260" ], + "spn": "SpeedTalk", "apns": [ { "name": "Cellular (MMS)",
@@ -14480,6 +14483,7 @@ "ids": [ "310260" ], + "spn": "Mint", "apns": [ { "name": "mint",
@@ -14495,6 +14499,7 @@ "ids": [ "310260" ], + "spn": "US Mobile", "apns": [ { "name": "US Mobile",
Signature · 1 line
2.43.0
PATCH v2 5/14 data: Remove outdated T-mobile settings
In reply to Denis Kenzior--- data/provision.json | 35 ----------------------------------- 1 file changed, 35 deletions(-)
data/provision.json +0 -35
@@ -14229,41 +14229,6 @@ "internet" ] }, - { - "name": "Internet/WebConnect", - "apn": "epc.tmobile.com", - "type": [ - "internet" - ] - }, - { - "name": "Web2Go/t-zones", - "apn": "wap.voicestream.com", - "type": [ - "internet" - ] - }, - { - "name": "Internet (old)", - "apn": "internet2.voicestream.com", - "type": [ - "internet" - ] - }, - { - "name": "Internet with VPN (old)", - "apn": "internet3.voicestream.com", - "type": [ - "internet" - ] - }, - { - "name": "Broadband", - "apn": "mobilenet", - "type": [ - "internet" - ] - }, { "name": "IoT", "apn": "iot.t-mobile.com",
Signature · 1 line
2.43.0
PATCH v2 6/14 data: Remove RESELLER settings from AT&T
In reply to Denis KenziorThis seems to be yet another MVNO, remove it for now.
--- data/provision.json | 10 ---------- 1 file changed, 10 deletions(-)
data/provision.json +0 -10
@@ -14181,16 +14181,6 @@ "mmsc": "http://mmsc.mobile.att.net", "mmsproxy": "proxy.mobile.att.net:80" }, - { - "name": "RESELLER", - "apn": "RESELLER", - "type": [ - "internet", - "mms" - ], - "mmsc": "http://mmsc.mobile.att.net", - "mmsproxy": "proxy.mobile.att.net:80" - }, { "name": "AT&T M2M", "apn": "m2m005246.attz",
Signature · 1 line
2.43.0
PATCH v2 7/14 provisiontool: Add support for context tags
In reply to Denis KenziorSince this changes the size of the context structure, bump the version number generated by provisiontool.
--- tools/provisiontool | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
tools/provisiontool +6 -4
@@ -24,7 +24,8 @@ class ProviderInfo: 'mmsproxy', 'authentication', 'username', - 'password'] ) } + 'password', + 'tags'] ) } @classmethod def rawimport(cls, entry):
@@ -228,12 +229,13 @@ class ProvisionContext(ctypes.LittleEndianStructure): ('username_offset', ctypes.c_uint64), ('password_offset', ctypes.c_uint64), ('mmsproxy_offset', ctypes.c_uint64), - ('mmsc_offset', ctypes.c_uint64) + ('mmsc_offset', ctypes.c_uint64), + ('tags_offset', ctypes.c_uint64), ] authentication_dict = { 'chap' : 0, 'pap' : 1, 'none' : 2 } protocol_dict = { 'ipv4' : 0, 'ipv6' : 1, 'ipv4v6' : 2 } - attrs = ['name', 'apn', 'username', 'password', 'mmsproxy', 'mmsc'] + attrs = ['name', 'apn', 'username', 'password', 'mmsproxy', 'mmsc', 'tags'] @classmethod def type_to_context_type(cls, types):
@@ -515,7 +517,7 @@ class ProvisionDatabase(ctypes.LittleEndianStructure): visitor.visit(self.tree.root) self.tree.traverse(visitor) - self.version = 1 + self.version = 2 self.header_size = ctypes.sizeof(ProvisionDatabase) self.file_size = self.header_size self.node_struct_size = ctypes.sizeof(ProvisionNode)
Signature · 1 line
2.43.0
PATCH v2 8/14 provisiondb: Add tags_filter support
In reply to Denis KenziorAlso update unit tests and other users of provisiondb APIs due to the API change.
--- src/provision.c | 3 ++- src/provisiondb.c | 54 ++++++++++++++++++++++++++++++++++--------- src/provisiondb.h | 2 ++ tools/lookup-apn.c | 2 +- unit/test-provision.c | 15 +++++++----- 5 files changed, 57 insertions(+), 19 deletions(-)
src/provision.c +2 -1
@@ -32,7 +32,8 @@ bool __ofono_provision_get_settings(const char *mcc,if (mcc ==NULL ||strlen (mcc) ==0 || mnc ==NULL ||strlen (mnc) ==0 )return false; - r =provision_db_lookup (pdb, mcc, mnc, spn, &contexts, &n_contexts); + r =provision_db_lookup (pdb, mcc, mnc, spn,NULL , + &contexts, &n_contexts);if (r <0 )return false;
src/provisiondb.c +43 -11
116 lines not on this page · raw message
src/provisiondb.h +2 -0
@@ -19,6 +19,7 @@ struct provision_db_entry {enum ofono_gprs_auth_method auth_method;const char *message_proxy;const char *message_center; +const char *tags; };struct provision_db *provision_db_new (const char *pathname);
@@ -27,5 +28,6 @@ void provision_db_free(struct provision_db *pdb);int provision_db_lookup (struct provision_db *pdb,const char *mcc,const char *mnc,const char *spn, +char **tags_filter,struct provision_db_entry **items,size_t *n_items);
tools/lookup-apn.c +1 -1
@@ -50,7 +50,7 @@ static int lookup_apn(const char *match_mcc, const char *match_mnc,fprintf (stdout,"Searching for info for network: %s%s, spn: %s\n" , match_mcc, match_mnc, match_spn ? match_spn :"<None>" ); - r =provision_db_lookup (pdb, match_mcc, match_mnc, match_spn, + r =provision_db_lookup (pdb, match_mcc, match_mnc, match_spn,NULL , &contexts, &n_contexts);if (r <0 ) {fprintf (stderr,"Unable to lookup: %s\n" ,strerror (-r));
unit/test-provision.c +9 -6
@@ -27,7 +27,8 @@ static void null_provision_db(const void *data)size_t n_items;int r; - r =provision_db_lookup (NULL ,"123" ,"345" ,NULL , &items, &n_items); + r =provision_db_lookup (NULL ,"123" ,"345" ,NULL ,NULL , + &items, &n_items);assert (r == -EBADF ); }
@@ -37,16 +38,18 @@ static void invalid_mcc_mnc(const void *data)size_t n_items;int r; - r =provision_db_lookup (pdb,"3444" ,"33" ,NULL , &items, &n_items); + r =provision_db_lookup (pdb,"3444" ,"33" ,NULL ,NULL , + &items, &n_items);assert (r == -EINVAL ); - r =provision_db_lookup (pdb,"3ab" ,"33" ,NULL , &items, &n_items); + r =provision_db_lookup (pdb,"3ab" ,"33" ,NULL ,NULL , &items, &n_items);assert (r == -EINVAL ); - r =provision_db_lookup (pdb,"333" ,"3" ,NULL , &items, &n_items); + r =provision_db_lookup (pdb,"333" ,"3" ,NULL ,NULL , &items, &n_items);assert (r == -EINVAL ); - r =provision_db_lookup (pdb,"333" ,"3334" ,NULL , &items, &n_items); + r =provision_db_lookup (pdb,"333" ,"3334" ,NULL ,NULL , + &items, &n_items);assert (r == -EINVAL ); }
@@ -225,7 +228,7 @@ static void provision_lookup(const void *data)size_t i;int r; - r =provision_db_lookup (pdb, test->mcc, test->mnc, test->spn, + r =provision_db_lookup (pdb, test->mcc, test->mnc, test->spn,NULL , &items, &n_items);assert (r == test->result);
Signature · 1 line
2.43.0
PATCH v2 9/14 tools: lookup-apn: add support for optional tags filter
In reply to Denis Kenzior--- tools/lookup-apn.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
tools/lookup-apn.c +18 -7
@@ -26,7 +26,7 @@static const char *option_file;static int lookup_apn (const char *match_mcc,const char *match_mnc, -const char *match_spn) +const char *match_spn,char **tags_filter) {struct provision_db *pdb;struct provision_db_entry *contexts;
@@ -50,7 +50,8 @@ static int lookup_apn(const char *match_mcc, const char *match_mnc,fprintf (stdout,"Searching for info for network: %s%s, spn: %s\n" , match_mcc, match_mnc, match_spn ? match_spn :"<None>" ); - r =provision_db_lookup (pdb, match_mcc, match_mnc, match_spn,NULL , + r =provision_db_lookup (pdb, match_mcc, match_mnc, + match_spn, tags_filter, &contexts, &n_contexts);if (r <0 ) {fprintf (stderr,"Unable to lookup: %s\n" ,strerror (-r));
@@ -78,6 +79,8 @@ static int lookup_apn(const char *match_mcc, const char *match_mnc,fprintf (stdout,"Message Center: %s\n" , ap->message_center); } + +fprintf (stdout,"Tags: %s\n" , ap->tags); }l_free (contexts);
@@ -92,22 +95,26 @@ static void usage(void)printf ("lookup-apn\nUsage:\n" );printf ("lookup-apn [options] <mcc> <mnc> [spn]\n" );printf ("Options:\n" -"\t-v, --version Show version\n" -"\t-f, --file Provision DB file to use\n" -"\t-h, --help Show help options\n" ); +"\t-v, --version Show version\n" +"\t-f, --file Provision DB file to use\n" +"\t-t, --tags Comma separated tag filter\n" +"\t-h, --help Show help options\n" ); }static const struct option options[] = { {"version" , no_argument,NULL ,'v' }, {"help" , no_argument,NULL ,'h' }, {"file" , required_argument,NULL ,'f' }, + {"tags" , required_argument,NULL ,'t' }, { }, };int main (int argc,char **argv) { + _auto_(l_strv_free) char **tags_filter = NULL; +for (;;) { -int opt =getopt_long (argc, argv,"f:vh" , options,NULL ); +int opt =getopt_long (argc, argv,"f:t:vh" , options,NULL );if (opt <0 )break ;
@@ -116,6 +123,9 @@ int main(int argc, char **argv)case 'f' : option_file = optarg;break ; +case 't' : + tags_filter =l_strsplit (optarg,',' ); +break ;case 'v' :printf ("%s\n" ,VERSION );return EXIT_SUCCESS ;
@@ -138,5 +148,6 @@ int main(int argc, char **argv) }return lookup_apn (argv[optind], argv[optind +1 ], - argc - optind ==3 ? argv[optind +2 ] :NULL ); + argc - optind ==3 ? argv[optind +2 ] :NULL , + tags_filter); }
Signature · 1 line
2.43.0
PATCH v2 10/14 data: Add tags for AT&T and T-Mobile contexts
In reply to Denis KenziorAT&T uses several APNs, one for lte/4g devices, one for 5G capable devices and one for M2M. Use the newly introduced tags field to tag them appropriately.
Similarly, for T-mobile, add "iot" tag to the iot specific APN configuration.
--- data/provision.json | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
data/provision.json +12 -6
@@ -14169,7 +14169,8 @@ "mms" ], "mmsc": "http://mmsc.mobile.att.net", - "mmsproxy": "proxy.mobile.att.net:80" + "mmsproxy": "proxy.mobile.att.net:80", + "tags": "lte" }, { "name": "ENHANCEDPHONE",
@@ -14179,7 +14180,8 @@ "mms" ], "mmsc": "http://mmsc.mobile.att.net", - "mmsproxy": "proxy.mobile.att.net:80" + "mmsproxy": "proxy.mobile.att.net:80", + "tags": "5g" }, { "name": "AT&T M2M",
@@ -14187,7 +14189,8 @@ "type": [ "internet", "ia" - ] + ], + "tags": "m2m" } ] },
@@ -14216,8 +14219,10 @@ "name": "T-Mobile LTE", "apn": "fast.t-mobile.com", "type": [ - "internet" - ] + "internet", + "ia" + ], + "tags": "lte,5g" }, { "name": "IoT",
@@ -14225,7 +14230,8 @@ "type": [ "internet", "ia" - ] + ], + "tags": "iot" } ] },
Signature · 1 line
2.43.0
PATCH v2 11/14 ofono: Add support for ofono main.conf settings
In reply to Denis KenziorIt would be useful to support some oFono wide configuration settings that can be configured for the system. Introduce a new __ofono_get_config() function that will obtain the parsed settings file as a pointer to l_settings. The settings will be parsed from the configuration directory set using CONFIGURATION_DIRECTORY environment variable, or the default CONFIGDIR variable set during configuration/compilation.
--- src/main.c | 32 ++++++++++++++++++++++++++++++++ src/ofono.h | 1 + 2 files changed, 33 insertions(+)
src/main.c +32 -0
@@ -39,6 +39,12 @@#define SHUTDOWN_GRACE_SECONDS 10static GMainLoop *event_loop; +static struct l_settings *ofono_config; + +const struct l_settings *__ofono_get_config (void ) +{ +return ofono_config; +}void __ofono_exit (void ) {
@@ -204,6 +210,9 @@ int main(int argc, char **argv)DBusError error;guint signal;struct ell_event_source *source; +const char *config_dir; +char **config_dirs; +unsigned int i; context =g_option_context_new (NULL );g_option_context_add_main_entries (context, options,NULL );
@@ -254,6 +263,27 @@ int main(int argc, char **argv)__ofono_log_init (argv[0 ], option_debug, option_detach); + config_dir =getenv ("CONFIGURATION_DIRECTORY" ); +if (!config_dir) + config_dir =CONFIGDIR ; + +l_debug ("Using configuration directory: %s" , config_dir); + config_dirs =l_strsplit (config_dir,':' ); + ofono_config =l_settings_new (); + +for (i =0 ; config_dirs[i]; i++) { + _auto_(l_free) char *path = l_strdup_printf("%s/main.conf", + config_dirs[i]); + +if (!l_settings_load_from_file (ofono_config, path)) +continue ; + +l_info ("Loaded configuration from %s" , path); +break ; + } + +l_strv_free (config_dirs); +dbus_error_init (&error); conn =g_dbus_setup_bus (DBUS_BUS_SYSTEM ,OFONO_SERVICE , &error);
@@ -291,6 +321,8 @@ fail_module_init:__ofono_dbus_cleanup ();dbus_connection_unref (conn); +l_settings_free (ofono_config); + cleanup:g_source_remove (signal);
src/ofono.h +1 -0
@@ -26,6 +26,7 @@#include <ofono/types.h> +const struct l_settings *__ofono_get_config (void );void __ofono_exit (void );int __ofono_handsfree_audio_manager_init (void );
Signature · 1 line
2.43.0
PATCH v2 12/14 provision: Add support for provision filter tags
In reply to Denis KenzioroFono main.conf configuration file can now contain an entry with group 'Provision' and key 'TagsFilter'. This entry is treated as a comma separated list of all tags that are accepted during context auto-provisioning. This can help to filter duplicate context entries from the provisioning database such that context auto-provisioning is successful without user intervention.
--- src/provision.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
src/provision.c +7 -2
@@ -28,12 +28,17 @@ bool __ofono_provision_get_settings(const char *mcc,int r;size_t i;uint32_t type; + _auto_(l_strv_free) char **tags_filter = NULL;if (mcc ==NULL ||strlen (mcc) ==0 || mnc ==NULL ||strlen (mnc) ==0 )return false; - r =provision_db_lookup (pdb, mcc, mnc, spn,NULL , - &contexts, &n_contexts); + tags_filter =l_settings_get_string_list (__ofono_get_config (), +"Provision" , +"TagsFilter" ,',' ); + + r =provision_db_lookup (pdb, mcc, mnc, spn, tags_filter, + &contexts, &n_contexts);if (r <0 )return false;
Signature · 1 line
2.43.0
PATCH v2 13/14 examples: Fix use after free and resource leaks
In reply to Denis KenziorThe emulator example plugin does not track modem powered watches, and thus leaks them. Additionally, the plugin opens ports for both HFP and DUN emulators. However, only a single server watch is tracked, leading to the other watch being leaked.
Since the modem powered watches are not tracked, they are never unregistered. This can lead to situations where emulator plugin is destroyed (and thus all data associated with it is freed) before all modems have been removed. When modems are removed subsequently, registered powered watches will be invoked. This will result in use-after-free errors being reported by valgrind.
--- examples/emulator.c | 151 +++++++++++++++++++++++++++++++------------- 1 file changed, 108 insertions(+), 43 deletions(-)
examples/emulator.c +108 -43
@@ -44,8 +44,48 @@#define HFP_PORT 12347static unsigned int modemwatch_id; -guint server_watch; -static GList *modems; +static guint dun_watch; +static guint hfp_watch; +static struct l_queue *modem_infos; +static unsigned int n_powered; + +struct modem_info { +struct ofono_modem *modem; +unsigned int watch_id; +}; + +static bool modem_matches (const void *data,const void *user_data) +{ +const struct modem_info *info = data; + +return info->modem == user_data; +} + +static void modem_info_free (struct modem_info *info) +{ +if (!info) +return ; + +if (info->watch_id) +__ofono_modem_remove_powered_watch (info->modem, info->watch_id); + +l_free (info); +} + +static struct ofono_modem *find_first_powered (void ) +{ +const struct l_queue_entry *entry; + +for (entry =l_queue_get_entries (modem_infos); entry; + entry = entry->next) { +struct ofono_modem *modem = entry->data; + +if (ofono_modem_get_powered (modem)) +return modem; + } + +return NULL ; +}static gboolean on_socket_connected (GIOChannel *chan,GIOCondition cond,gpointer user)
@@ -64,28 +104,35 @@ static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,return FALSE;/* Pick the first powered modem */ - modem = modems->data; + modem =find_first_powered (); +if (!modem) + goto error; +DBG ("Picked modem %p for emulator" , modem); em =ofono_emulator_create (modem,GPOINTER_TO_INT (user)); -if (em ==NULL ) -close (fd); -else -ofono_emulator_register (em, fd); +if (!em) + goto error; + +ofono_emulator_register (em, fd); +return TRUE; +error: +close (fd);return TRUE; } -static gboolean create_tcp (short port,enum ofono_emulator_type type) +static guint create_tcp (short port,enum ofono_emulator_type type) {struct sockaddr_in addr;int sk;int reuseaddr =1 ;GIOChannel *server; +guint server_watch; sk =socket (PF_INET ,SOCK_STREAM ,0 );if (sk <0 ) -return FALSE; +return 0 ;memset (&addr,0 ,sizeof (addr));
@@ -108,62 +155,77 @@ static gboolean create_tcp(short port, enum ofono_emulator_type type)G_IO_IN |G_IO_HUP |G_IO_ERR |G_IO_NVAL , on_socket_connected,GINT_TO_POINTER (type), NULL); -g_io_channel_unref (server);DBG ("Created server_watch: %u" , server_watch); - -return TRUE; +return server_watch; err:close (sk); -return FALSE; +return 0 ; +} + +static void powered_watch_destroy (void *user) +{ +struct modem_info *info = user; + +DBG ("" ); + + info->watch_id =0 ; }static void powered_watch (struct ofono_modem *modem,gboolean powered,void *user) { +DBG ("powered: %d" , powered); +if (powered == FALSE) { -DBG ("Removing modem %p from the list" , modem); - modems =g_list_remove (modems, modem); - -if (modems ==NULL && server_watch >0 ) { -DBG ("Removing server watch: %u" , server_watch); -g_source_remove (server_watch); - server_watch =0 ; - } - }else { -DBG ("Adding modem %p to the list" , modem); - modems =g_list_append (modems, modem); - -if (modems->next ==NULL ) { -create_tcp (DUN_PORT ,OFONO_EMULATOR_TYPE_DUN ); -create_tcp (HFP_PORT ,OFONO_EMULATOR_TYPE_HFP ); - } + n_powered -=1 ; + +if (n_powered) +return ; + +g_source_remove (dun_watch); + dun_watch =0 ; + +g_source_remove (hfp_watch); + hfp_watch =0 ; + +return ; } + + n_powered +=1 ; + +if (!dun_watch) + dun_watch =create_tcp (DUN_PORT ,OFONO_EMULATOR_TYPE_DUN ); + +if (!hfp_watch) + hfp_watch =create_tcp (HFP_PORT ,OFONO_EMULATOR_TYPE_HFP ); }static void modem_watch (struct ofono_modem *modem,gboolean added,void *user) { +struct modem_info *info; +DBG ("modem: %p, added: %d" , modem, added);if (added == FALSE) { -DBG ("Removing modem %p from the list" , modem); - modems =g_list_remove (modems, modem); + info =l_queue_remove_if (modem_infos, modem_matches, modem); +DBG ("Removing modem %p, info %p, from the list" , modem, info); +modem_info_free (info);return ; } -if (ofono_modem_get_powered (modem) == TRUE) { -DBG ("Adding modem %p to the list" , modem); - modems =g_list_append (modems, modem); + info = l_new(struct modem_info, 1); + info->modem = modem; + info->watch_id =__ofono_modem_add_powered_watch (modem, powered_watch, + info, + powered_watch_destroy); -if (modems->next ==NULL ) { -create_tcp (DUN_PORT ,OFONO_EMULATOR_TYPE_DUN ); -create_tcp (HFP_PORT ,OFONO_EMULATOR_TYPE_HFP ); - } - } +l_queue_push_tail (modem_infos, info); -__ofono_modem_add_powered_watch (modem, powered_watch,NULL ,NULL ); +if (ofono_modem_get_powered (modem) == TRUE) +powered_watch (modem, TRUE,NULL ); }static void call_modemwatch (struct ofono_modem *modem,void *user)
@@ -175,6 +237,7 @@ static int example_emulator_init(void) {DBG ("" ); + modem_infos =l_queue_new (); modemwatch_id =__ofono_modemwatch_add (modem_watch,NULL ,NULL );__ofono_modem_foreach (call_modemwatch,NULL );
@@ -187,11 +250,13 @@ static void example_emulator_exit(void)DBG ("" );__ofono_modemwatch_remove (modemwatch_id); +l_queue_destroy (modem_infos, (l_queue_destroy_func_t ) modem_info_free); -g_list_free (modems); +if (dun_watch) +g_source_remove (dun_watch); -if (server_watch) -g_source_remove (server_watch); +if (hfp_watch) +g_source_remove (hfp_watch); } OFONO_PLUGIN_DEFINE(example_emulator, "Example AT Modem Emulator Plugin",
Signature · 1 line
2.43.0
PATCH v2 14/14 unit: Add test cases with tags_filter provided
In reply to Denis KenziorReplace the XYZ operator contexts with a set of two. One tagged as 'lte' and one tagged as '5g'. Add logic to the provision unit test to support filter tags.
--- unit/test-provision.c | 37 +++++++++++++++++++++++++++++++------ unit/test-provision.json | 10 +++++++++- 2 files changed, 40 insertions(+), 7 deletions(-)
unit/test-provision.c +31 -6
@@ -57,6 +57,7 @@ struct provision_test {const char *mcc;const char *mnc;const char *spn; +const char *tags;int result;size_t n_items;const struct provision_db_entry *items;
@@ -114,7 +115,7 @@ static const struct provision_db_entry charlie_contexts[] = { }, }; -static const struct provision_db_entry xyz_contexts[] = { +static const struct provision_db_entry xyz_lte_contexts[] = { { .type =OFONO_GPRS_CONTEXT_TYPE_INTERNET |OFONO_GPRS_CONTEXT_TYPE_IA ,
@@ -124,6 +125,16 @@ static const struct provision_db_entry xyz_contexts[] = { } }; +static const struct provision_db_entry xyz_5g_contexts[] = { + { + .type =OFONO_GPRS_CONTEXT_TYPE_INTERNET | +OFONO_GPRS_CONTEXT_TYPE_IA , + .proto =OFONO_GPRS_PROTO_IPV4V6 , + .apn ="xyz.5g" , + .auth_method =OFONO_GPRS_AUTH_METHOD_CHAP , + } +}; +/* Make sure mccmnc not in the database isn't found */ static const struct provision_test unknown_mcc_mnc = { .mcc ="994" ,
@@ -204,13 +215,25 @@ static const struct provision_test lookup_charlie = { };/* Successful lookup of XYZ (MVNO on Charlie) */ -static const struct provision_test lookup_xyz = { +static const struct provision_test lookup_lte_xyz = { + .mcc ="999" , + .mnc ="11" , + .spn ="XYZ" , + .tags ="lte,unused" , + .result =0 , + .n_items =L_ARRAY_SIZE (xyz_lte_contexts), + .items = xyz_lte_contexts, +}; + +/* Successful lookup of XYZ (MVNO on Charlie) */ +static const struct provision_test lookup_5g_xyz = { .mcc ="999" , .mnc ="11" , .spn ="XYZ" , + .tags ="5g" , .result =0 , - .n_items =L_ARRAY_SIZE (xyz_contexts), - .items = xyz_contexts, + .n_items =L_ARRAY_SIZE (xyz_5g_contexts), + .items = xyz_5g_contexts, };/* No match with for an MCC/MNC present in the DB, but no wildcard entry */
@@ -224,11 +247,12 @@ static void provision_lookup(const void *data) {const struct provision_test *test = data;struct provision_db_entry *items; + _auto_(l_strv_free) char **tags = l_strsplit(test->tags, ',');size_t n_items;size_t i;int r; - r =provision_db_lookup (pdb, test->mcc, test->mnc, test->spn,NULL , + r =provision_db_lookup (pdb, test->mcc, test->mnc, test->spn, tags, &items, &n_items);assert (r == test->result);
@@ -270,7 +294,8 @@ int main(int argc, char **argv)l_test_add ("Successful lookup (Alpha)" , provision_lookup, &lookup_alpha);l_test_add ("Successful lookup (ZYX)" , provision_lookup, &lookup_zyx);l_test_add ("Exact match (Charlie)" , provision_lookup, &lookup_charlie); -l_test_add ("Exact match (XYZ)" , provision_lookup, &lookup_xyz); +l_test_add ("Exact match (XYZ)" , provision_lookup, &lookup_lte_xyz); +l_test_add ("Exact match (XYZ 5G)" , provision_lookup, &lookup_5g_xyz);l_test_add ("Exact math (no match)" , provision_lookup, &lookup_no_match); pdb =provision_db_new (UNITDIR "test-provision.db" );
unit/test-provision.json +9 -1
@@ -85,7 +85,15 @@ "apn": "xyz", "type": [ "internet", "ia" - ] + ], + "tags": "lte" + }, + { + "apn": "xyz.5g", + "type": [ + "internet", "ia" + ], + "tags": "5g" } ] }
Signature · 1 line
2.43.0
This series was applied to ofono.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to ofono.git (master)
by Denis Kenzior <[email protected]>:
Quoted 10 lines · On Wed, 3 Apr 2024 11:05:24 -0500 you wrote:
While here, also remove
sim_eons_optimize()as it is no longer needed. The ell queue implementation natively supports pushing to the back of a linked list. Also tighten up some length checks and make 'length' arguments unsigned.--- src/network.c | 2 - src/simutil.c | 116 +++++++++++++++++++++----------------------- src/simutil.h | 15 +++--- unit/test-simutil.c | 1 - 4 files changed, 63 insertions(+), 71 deletions(-)
Here is the summary with links:
- [v2,01/14] simutil: Convert eons APIs to use ell
https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=9850e63ef1da - [v2,02/14] sim: Simplify SPN management logic https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=4a6c0786bea2 - [v2,03/14] data: Remove AweSIM entry https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=ec4946390408 - [v2,04/14] data: Mark some MVNOs via the "spn" attribute https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=b37e70242b4e - [v2,05/14] data: Remove outdated T-mobile settings https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=5594561c1f4f - [v2,06/14] data: Remove RESELLER settings from AT&T https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=c496380af19e - [v2,07/14] provisiontool: Add support for context tags https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=407309cf47f0 - [v2,08/14] provisiondb: Add tags_filter support https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=61fbfea7e46d - [v2,09/14] tools: lookup-apn: add support for optional tags filter https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=bf76c826774f - [v2,10/14] data: Add tags for AT&T and T-Mobile contexts https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=5072741ab979 - [v2,11/14] ofono: Add support for ofono main.conf settings (no matching commit) - [v2,12/14] provision: Add support for provision filter tags https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=00cc10773680 - [v2,13/14] examples: Fix use after free and resource leaks https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=64e2380f4b37 - [v2,14/14] unit: Add test cases with tags_filter provided https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=393b6cc3dcbe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html