Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions plugins/mbpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>

#include <glib.h>

#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/modem.h>
#include <ofono/gprs-provision.h>

#ifndef MBPI_DATABASE
#define MBPI_DATABASE "/usr/share/mobile-broadband-provider-info/" \
"serviceproviders.xml"
#endif
#define MBPI_FILE "serviceproviders.xml"
#define MBPI_DATABASE "/usr/share/mobile-broadband-provider-info/" MBPI_FILE

#include "mbpi.h"

Expand Down Expand Up @@ -110,7 +109,7 @@ static void mbpi_g_set_error(GMarkupParseContext *context, GError **error,

va_end(ap);

g_prefix_error(error, "%s:%d ", MBPI_DATABASE, line_number);
g_prefix_error(error, "%s:%d ", MBPI_FILE, line_number);
}

static void text_handler(GMarkupParseContext *context,
Expand Down Expand Up @@ -565,34 +564,40 @@ static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
char *db;
int fd;
GMarkupParseContext *context;
gboolean ret;
gboolean ret = FALSE;
const char *snap;
char *filename;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short comment that explains the SNAP env variable.

/* SNAP is a path to our data in snappy systems */
snap = getenv("SNAP");
filename = g_strdup_printf("%s%s", snap ? snap : "", MBPI_DATABASE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should discuss where mbpi ends up living as it's used by modemmanager too.

I think it probably should live in it's own snap that shares the file via content sharing. We also should explore the ability for an end-user to modify this file on a working system ( ie. allow a writable version that would override the default ) vs. forcing the user to report a bug and wait for an official update.


fd = open(MBPI_DATABASE, O_RDONLY);
fd = open(filename, O_RDONLY);
if (fd < 0) {
g_set_error(error, G_FILE_ERROR,
g_file_error_from_errno(errno),
"open(%s) failed: %s", MBPI_DATABASE,
"open(%s) failed: %s", filename,
g_strerror(errno));
return FALSE;
goto done;
}

if (fstat(fd, &st) < 0) {
close(fd);
g_set_error(error, G_FILE_ERROR,
g_file_error_from_errno(errno),
"fstat(%s) failed: %s", MBPI_DATABASE,
"fstat(%s) failed: %s", filename,
g_strerror(errno));
return FALSE;
goto done;
}

db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (db == MAP_FAILED) {
close(fd);
g_set_error(error, G_FILE_ERROR,
g_file_error_from_errno(errno),
"mmap(%s) failed: %s", MBPI_DATABASE,
"mmap(%s) failed: %s", filename,
g_strerror(errno));
return FALSE;
goto done;
}

context = g_markup_parse_context_new(parser,
Expand All @@ -608,6 +613,8 @@ static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
close(fd);
g_markup_parse_context_free(context);

done:
g_free(filename);
return ret;
}

Expand Down
17 changes: 14 additions & 3 deletions plugins/phonesim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,20 @@ static void parse_config(void)
char **modems;
int i;
const char *filename;
char *snap_filename = NULL;
const char *conf_override = getenv("OFONO_PHONESIM_CONFIG");
/* SNAP_COMMON gives us a writable path for daemons in snappy systems */
const char *snap_common = getenv("SNAP_COMMON");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short comment explaining why SNAP_COMMON is used here.


char *conf_override = getenv("OFONO_PHONESIM_CONFIG");
if (conf_override)
if (conf_override) {
filename = conf_override;
else
} else if (snap_common) {
snap_filename = g_strdup_printf("%s/etc/phonesim.conf",
snap_common);
filename = snap_filename;
} else {
filename = CONFIGDIR "/phonesim.conf";
}

DBG("filename %s", filename);

Expand Down Expand Up @@ -1143,6 +1151,9 @@ static void parse_config(void)
g_strfreev(modems);

done:
if (snap_filename)
g_free(snap_filename);

g_key_file_free(keyfile);
}

Expand Down
11 changes: 10 additions & 1 deletion plugins/u8500.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,18 @@ static void u8500_query_serial(struct ofono_devinfo *info,
{
char imei[16]; /* IMEI 15 digits + 1 null*/
char numbers[] = "1234567890";
FILE *fp = fopen("/etc/imei", "r");
FILE *fp;
char *imei_file;
/* SNAP_COMMON gives us a writable path for daemons in snappy systems */
const char *snap_common = getenv("SNAP_COMMON");

DBG("");

imei_file = g_strdup_printf("%s/etc/imei",
snap_common ? snap_common : "");
fp = fopen(imei_file, "r");
g_free(imei_file);

if (fp == NULL) {
DBG("failed to open /etc/imei file");
goto error;
Expand Down
40 changes: 25 additions & 15 deletions src/simfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
#include "storage.h"

#define SIM_CACHE_MODE 0600
#define SIM_CACHE_BASEPATH STORAGEDIR "/%s-%i"
#define SIM_CACHE_BASEPATH "%s/%s-%i"
#define SIM_CACHE_VERSION SIM_CACHE_BASEPATH "/version"
#define SIM_CACHE_PATH SIM_CACHE_BASEPATH "/%04x"
#define SIM_CACHE_HEADER_SIZE 39
#define SIM_FILE_INFO_SIZE 7
#define SIM_IMAGE_CACHE_BASEPATH STORAGEDIR "/%s-%i/images"
#define SIM_IMAGE_CACHE_BASEPATH "%s/%s-%i/images"
#define SIM_IMAGE_CACHE_PATH SIM_IMAGE_CACHE_BASEPATH "/%d.xpm"

#define SIM_FS_VERSION 2
Expand Down Expand Up @@ -653,7 +653,8 @@ static void sim_fs_op_cache_fileinfo(struct sim_fs *fs,
fileinfo[5] = record_length & 0xff;
fileinfo[6] = file_status;

path = g_strdup_printf(SIM_CACHE_PATH, imsi, phase, op->id);
path = g_strdup_printf(SIM_CACHE_PATH,
storage_dir(), imsi, phase, op->id);
fs->fd = TFR(open(path, O_WRONLY | O_CREAT | O_TRUNC, SIM_CACHE_MODE));
g_free(path);

Expand Down Expand Up @@ -750,7 +751,8 @@ static gboolean sim_fs_op_check_cached(struct sim_fs *fs)
if (imsi == NULL || phase == OFONO_SIM_PHASE_UNKNOWN)
return FALSE;

path = g_strdup_printf(SIM_CACHE_PATH, imsi, phase, op->id);
path = g_strdup_printf(SIM_CACHE_PATH,
storage_dir(), imsi, phase, op->id);

if (path == NULL)
return FALSE;
Expand Down Expand Up @@ -1117,8 +1119,8 @@ void sim_fs_cache_image(struct sim_fs *fs, const char *image, int id)
return;

write_file((const unsigned char *) image, strlen(image),
SIM_CACHE_MODE, SIM_IMAGE_CACHE_PATH, imsi,
phase, id);
SIM_CACHE_MODE, SIM_IMAGE_CACHE_PATH,
storage_dir(), imsi, phase, id);
}

char *sim_fs_get_cached_image(struct sim_fs *fs, int id)
Expand All @@ -1143,7 +1145,8 @@ char *sim_fs_get_cached_image(struct sim_fs *fs, int id)
if (phase == OFONO_SIM_PHASE_UNKNOWN)
return NULL;

path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id);
path = g_strdup_printf(SIM_IMAGE_CACHE_PATH,
storage_dir(), imsi, phase, id);

TFR(stat(path, &st_buf));
fd = TFR(open(path, O_RDONLY));
Expand Down Expand Up @@ -1183,7 +1186,7 @@ static void remove_cachefile(const char *imsi, enum ofono_sim_phase phase,
if (sscanf(file->d_name, "%4x", &id) != 1)
return;

path = g_strdup_printf(SIM_CACHE_PATH, imsi, phase, id);
path = g_strdup_printf(SIM_CACHE_PATH, storage_dir(), imsi, phase, id);
remove(path);
g_free(path);
}
Expand All @@ -1200,7 +1203,8 @@ static void remove_imagefile(const char *imsi, enum ofono_sim_phase phase,
if (sscanf(file->d_name, "%d", &id) != 1)
return;

path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id);
path = g_strdup_printf(SIM_IMAGE_CACHE_PATH,
storage_dir(), imsi, phase, id);
remove(path);
g_free(path);
}
Expand All @@ -1214,21 +1218,24 @@ void sim_fs_check_version(struct sim_fs *fs)
if (imsi == NULL || phase == OFONO_SIM_PHASE_UNKNOWN)
return;

if (read_file(&version, 1, SIM_CACHE_VERSION, imsi, phase) == 1)
if (read_file(&version, 1, SIM_CACHE_VERSION,
storage_dir(), imsi, phase) == 1)
if (version == SIM_FS_VERSION)
return;

sim_fs_cache_flush(fs);

version = SIM_FS_VERSION;
write_file(&version, 1, SIM_CACHE_MODE, SIM_CACHE_VERSION, imsi, phase);
write_file(&version, 1, SIM_CACHE_MODE, SIM_CACHE_VERSION,
storage_dir(), imsi, phase);
}

void sim_fs_cache_flush(struct sim_fs *fs)
{
const char *imsi = ofono_sim_get_imsi(fs->sim);
enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
char *path = g_strdup_printf(SIM_CACHE_BASEPATH, imsi, phase);
char *path = g_strdup_printf(SIM_CACHE_BASEPATH,
storage_dir(), imsi, phase);
struct dirent **entries;
int len = scandir(path, &entries, NULL, alphasort);

Expand All @@ -1251,7 +1258,8 @@ void sim_fs_cache_flush_file(struct sim_fs *fs, int id)
{
const char *imsi = ofono_sim_get_imsi(fs->sim);
enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
char *path = g_strdup_printf(SIM_CACHE_PATH, imsi, phase, id);
char *path = g_strdup_printf(SIM_CACHE_PATH,
storage_dir(), imsi, phase, id);

remove(path);
g_free(path);
Expand All @@ -1261,7 +1269,8 @@ void sim_fs_image_cache_flush(struct sim_fs *fs)
{
const char *imsi = ofono_sim_get_imsi(fs->sim);
enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
char *path = g_strdup_printf(SIM_IMAGE_CACHE_BASEPATH, imsi, phase);
char *path = g_strdup_printf(SIM_IMAGE_CACHE_BASEPATH,
storage_dir(), imsi, phase);
struct dirent **entries;
int len = scandir(path, &entries, NULL, alphasort);

Expand All @@ -1283,7 +1292,8 @@ void sim_fs_image_cache_flush_file(struct sim_fs *fs, int id)
{
const char *imsi = ofono_sim_get_imsi(fs->sim);
enum ofono_sim_phase phase = ofono_sim_get_phase(fs->sim);
char *path = g_strdup_printf(SIM_IMAGE_CACHE_PATH, imsi, phase, id);
char *path = g_strdup_printf(SIM_IMAGE_CACHE_PATH,
storage_dir(), imsi, phase, id);

remove(path);
g_free(path);
Expand Down
Loading