From 1789f2ac0766851f078c754fe31cb87a6f013184 Mon Sep 17 00:00:00 2001 From: PaulK Date: Fri, 3 Feb 2012 20:21:36 +0100 Subject: Modified ipc devices handling to use a table and permit explicit device name --- Android.mk | 1 + include/radio.h | 10 ---- samsung-ipc/Makefile.am | 1 + samsung-ipc/device/aries/aries_ipc.c | 6 --- samsung-ipc/device/crespo/crespo_ipc.c | 6 --- samsung-ipc/device/h1/h1_ipc.c | 4 +- samsung-ipc/ipc.c | 78 +++++++++++++++---------------- samsung-ipc/ipc_devices.c | 33 +++++++++++++ samsung-ipc/ipc_devices.h | 57 +++++++++++++++++++++++ samsung-ipc/ipc_private.h | 6 --- tools/modemctrl.c | 84 +++++++++++++--------------------- 11 files changed, 165 insertions(+), 121 deletions(-) create mode 100644 samsung-ipc/ipc_devices.c create mode 100644 samsung-ipc/ipc_devices.h diff --git a/Android.mk b/Android.mk index 11d941f..8997e80 100644 --- a/Android.mk +++ b/Android.mk @@ -37,6 +37,7 @@ endif samsung-ipc_files := \ samsung-ipc/ipc.c \ samsung-ipc/ipc_util.c \ + samsung-ipc/ipc_devices.c \ samsung-ipc/util.c \ samsung-ipc/rfs.c \ samsung-ipc/gen.c \ diff --git a/include/radio.h b/include/radio.h index 4c14d79..3cd8834 100644 --- a/include/radio.h +++ b/include/radio.h @@ -29,11 +29,6 @@ #define IPC_CLIENT_TYPE_FMT 0 #define IPC_CLIENT_TYPE_RFS 1 -#define IPC_DEVICE_CRESPO 0 -#define IPC_DEVICE_ARIES 1 - -#define IPC_DEVICE_MAX IPC_DEVICE_ARIES - #define IPC_COMMAND(f) ((f->group << 8) | f->index) #define IPC_GROUP(m) (m >> 8) #define IPC_INDEX(m) (m & 0xff) @@ -57,11 +52,6 @@ struct ipc_message_info { struct ipc_client; struct ipc_handlers; -extern struct ipc_handlers ipc_default_handlers; - -void ipc_init(void); -void ipc_shutdown(void); - typedef void (*ipc_client_log_handler_cb)(const char *message, void *user_data); typedef int (*ipc_io_handler_cb)(void *data, unsigned int size, void *io_data); diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am index 31c3934..df5dc22 100644 --- a/samsung-ipc/Makefile.am +++ b/samsung-ipc/Makefile.am @@ -17,6 +17,7 @@ lib_LTLIBRARIES = \ libsamsung_ipc_la_SOURCES = \ ipc.c \ ipc_util.c \ + ipc_devices.c \ util.c \ \ rfs.c \ diff --git a/samsung-ipc/device/aries/aries_ipc.c b/samsung-ipc/device/aries/aries_ipc.c index 5010017..7f6749d 100644 --- a/samsung-ipc/device/aries/aries_ipc.c +++ b/samsung-ipc/device/aries/aries_ipc.c @@ -941,10 +941,4 @@ struct ipc_ops aries_rfs_ops = { .bootstrap = NULL, }; -void aries_ipc_register(void) -{ - ipc_register_device_client_handlers(IPC_DEVICE_ARIES, &aries_fmt_ops, - &aries_rfs_ops, &aries_default_handlers); -} - // vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/device/crespo/crespo_ipc.c b/samsung-ipc/device/crespo/crespo_ipc.c index 0ce7830..556d77c 100644 --- a/samsung-ipc/device/crespo/crespo_ipc.c +++ b/samsung-ipc/device/crespo/crespo_ipc.c @@ -717,10 +717,4 @@ struct ipc_ops crespo_rfs_ops = { .bootstrap = NULL, }; -void crespo_ipc_register(void) -{ - ipc_register_device_client_handlers(IPC_DEVICE_CRESPO, &crespo_fmt_ops, - &crespo_rfs_ops, &crespo_default_handlers); -} - // vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/device/h1/h1_ipc.c b/samsung-ipc/device/h1/h1_ipc.c index 8363449..1f6b825 100644 --- a/samsung-ipc/device/h1/h1_ipc.c +++ b/samsung-ipc/device/h1/h1_ipc.c @@ -263,7 +263,7 @@ int h1_ipc_common_data_get_fd(void *io_data) return (int) *(common_data); } -struct ipc_handlers ipc_default_handlers = { +struct ipc_handlers h1_default_handlers = { .open = h1_ipc_open, .close = h1_ipc_close, .power_on = h1_ipc_power_on, @@ -277,7 +277,7 @@ struct ipc_handlers ipc_default_handlers = { .common_data_get_fd = h1_ipc_common_data_get_fd, }; -struct ipc_ops ipc_fmt_ops = { +struct ipc_ops h1_fmt_ops = { .send = h1_ipc_send, .recv = h1_ipc_recv, .bootstrap = NULL, diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c index 60f5db0..970dfa1 100644 --- a/samsung-ipc/ipc.c +++ b/samsung-ipc/ipc.c @@ -38,35 +38,13 @@ #include #include "ipc_private.h" - -struct ipc_device_desc devices[IPC_DEVICE_MAX+1]; - -extern void crespo_ipc_register(void); -extern void aries_ipc_register(); - -void ipc_init(void) -{ - crespo_ipc_register(); - aries_ipc_register(); -} - -void ipc_shutdown(void) -{ -} +#include "ipc_devices.h" void log_handler_default(const char *message, void *user_data) { printf("%s\n", message); } -void ipc_register_device_client_handlers(int device, struct ipc_ops *fmt_ops, - struct ipc_ops *rfs_ops, struct ipc_handlers *handlers) -{ - devices[device].fmt_ops = fmt_ops; - devices[device].rfs_ops = rfs_ops; - devices[device].handlers = handlers; -} - void ipc_client_log(struct ipc_client *client, const char *message, ...) { assert(client->log_handler != NULL); @@ -80,9 +58,21 @@ void ipc_client_log(struct ipc_client *client, const char *message, ...) va_end(args); } -struct ipc_client* ipc_client_new(int client_type) +int ipc_device_detect(void) { - int device_type = -1, in_hardware = 0; + int index = -1; + int i; + +#ifdef IPC_DEVICE_EXPLICIT + for(i=0 ; i < ipc_devices_count ; i++) + { + if(strcmp(IPC_DEVICE_EXPLICIT, ipc_device[i].name) == 0) + { + index = i; + break; + } + } +#else char buf[4096]; // gather device type from /proc/cpuinfo @@ -97,27 +87,34 @@ struct ipc_client* ipc_client_new(int client_type) int rc; if ((rc = strncmp(pch, "Hardware", 9)) == 9) { - if (strstr(pch, "herring") != NULL) - device_type = IPC_DEVICE_CRESPO; + for(i=0 ; i < ipc_devices_count ; i++) + { + if(strcmp(pch, ipc_devices[i].board_name) == 0) + { + index = i; + break; + } + } } pch = strtok(NULL, "\n"); } +#endif - // validate that we have found any supported device - if (device_type == -1) - return NULL; - - return ipc_client_new_for_device(device_type, client_type); + return index; } -struct ipc_client* ipc_client_new_for_device(int device_type, int client_type) +struct ipc_client* ipc_client_new(int client_type) { struct ipc_client *client; + int device_index = -1; + + device_index = ipc_device_detect(); + + if(device_index < 0 || device_index > ipc_devices_count) + return NULL; - if (device_type < 0 || device_type > IPC_DEVICE_MAX) - return 0; if (client_type < 0 || client_type > IPC_CLIENT_TYPE_RFS) - return 0; + return NULL; client = (struct ipc_client*) malloc(sizeof(struct ipc_client)); client->type = client_type; @@ -125,17 +122,18 @@ struct ipc_client* ipc_client_new_for_device(int device_type, int client_type) switch (client_type) { case IPC_CLIENT_TYPE_RFS: - client->ops = devices[device_type].rfs_ops; + client->ops = ipc_devices[device_index].rfs_ops; break; case IPC_CLIENT_TYPE_FMT: - client->ops = devices[device_type].fmt_ops; + client->ops = ipc_devices[device_index].fmt_ops; break; } client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers)); client->log_handler = log_handler_default; - if (devices[device_type].handlers != 0) - memcpy(client->handlers, devices[device_type].handlers , sizeof(struct ipc_handlers)); + + if (ipc_devices[device_index].handlers != 0) + memcpy(client->handlers, ipc_devices[device_index].handlers, sizeof(struct ipc_handlers)); return client; } diff --git a/samsung-ipc/ipc_devices.c b/samsung-ipc/ipc_devices.c new file mode 100644 index 0000000..f3f2b17 --- /dev/null +++ b/samsung-ipc/ipc_devices.c @@ -0,0 +1,33 @@ +/** + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2012 Paul Kocialkowski + * + * libsamsung-ipc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libsamsung-ipc. If not, see . + * + */ + +#include + +#include "ipc_devices.h" + +struct ipc_device_desc ipc_devices[] = { + { "crespo", "herring", &crespo_default_handlers, &crespo_fmt_ops, &crespo_rfs_ops }, + { "aries", "aries", &aries_default_handlers, &aries_fmt_ops, &aries_rfs_ops }, + { "aries", "gt-p1000", &aries_default_handlers, &aries_fmt_ops, &aries_rfs_ops } +}; + +int ipc_devices_count = sizeof(ipc_devices) / sizeof(struct ipc_device_desc); + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/ipc_devices.h b/samsung-ipc/ipc_devices.h new file mode 100644 index 0000000..baddb76 --- /dev/null +++ b/samsung-ipc/ipc_devices.h @@ -0,0 +1,57 @@ +/** + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2012 Paul Kocialkowski + * + * libsamsung-ipc is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libsamsung-ipc. If not, see . + * + */ + +#ifndef __IPC_DEVICES_H__ +#define __IPC_DEVICES_H__ + +#include + +struct ipc_device_desc { + char *name; + char *board_name; + + struct ipc_handlers *handlers; + struct ipc_ops *fmt_ops; + struct ipc_ops *rfs_ops; +}; + +extern struct ipc_device_desc ipc_devices[]; +extern int ipc_devices_count; + +// h1 + +extern struct ipc_handlers h1_default_handlers; +extern struct ipc_ops h1_fmt_ops; +extern struct ipc_ops h1_rfs_ops; + +// crespo + +extern struct ipc_handlers crespo_default_handlers; +extern struct ipc_ops crespo_fmt_ops; +extern struct ipc_ops crespo_rfs_ops; + +// aries +extern struct ipc_handlers aries_default_handlers; +extern struct ipc_ops aries_fmt_ops; +extern struct ipc_ops aries_rfs_ops; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/ipc_private.h b/samsung-ipc/ipc_private.h index 1795def..ac8db78 100644 --- a/samsung-ipc/ipc_private.h +++ b/samsung-ipc/ipc_private.h @@ -65,12 +65,6 @@ struct ipc_client { struct ipc_handlers *handlers; }; -struct ipc_device_desc { - struct ipc_ops *fmt_ops; - struct ipc_ops *rfs_ops; - struct ips_handlers *handlers; -}; - void ipc_client_log(struct ipc_client *client, const char *message, ...); void ipc_register_device_client_handlers(int device, struct ipc_ops *fmt_ops, struct ipc_ops *rfs_ops, struct ipc_handlers *handlers); diff --git a/tools/modemctrl.c b/tools/modemctrl.c index d96a751..5825ec7 100644 --- a/tools/modemctrl.c +++ b/tools/modemctrl.c @@ -190,7 +190,7 @@ void modem_response_sec(struct ipc_client *client, struct ipc_message_info *resp printf("[3] SIM init complete\n"); if(state == MODEM_STATE_NORMAL) state = MODEM_STATE_SIM_OK; - + break; case IPC_SEC_PIN_SIM_PB_INIT_COMPLETE: printf("[I] SIM Phone Book init complete\n"); @@ -278,7 +278,7 @@ void modem_response_call(struct ipc_client *client, struct ipc_message_info *res modem_snd_no_mic_mute(client); } break; - } + } } void modem_response_pwr(struct ipc_client *client, struct ipc_message_info *resp) @@ -484,12 +484,10 @@ int main(int argc, char *argv[]) { struct ipc_client *client_fmt; int c = 0; - int opt_i = 0; + int opt_i = 0; int rc = -1; - int debug = 0; struct option opt_l[] = { - {"help", no_argument, 0, 0 }, {"debug", no_argument, 0, 0 }, {"pin", required_argument, 0, 0 }, {0, 0, 0, 0 } @@ -500,6 +498,9 @@ int main(int argc, char *argv[]) exit(1); } + client_fmt = ipc_client_new(IPC_CLIENT_TYPE_FMT); + ipc_client_set_log_handler(client_fmt, modem_log_handler_quiet, NULL); + while(c >= 0) { c = getopt_long(argc, argv, "", opt_l, &opt_i); if(c < 0) @@ -507,11 +508,8 @@ int main(int argc, char *argv[]) switch(c) { case 0: - if (strncmp(opt_l[opt_i].name, "help", 4) == 0) { - print_help(); - exit(1); - } else if(strcmp(opt_l[opt_i].name, "debug") == 0) { - debug = 1; + if(strcmp(opt_l[opt_i].name, "debug") == 0) { + ipc_client_set_log_handler(client_fmt, modem_log_handler, NULL); printf("[I] Debug enabled\n"); } else if(strcmp(opt_l[opt_i].name, "pin") == 0) { if(optarg) { @@ -528,56 +526,40 @@ int main(int argc, char *argv[]) } } - ipc_init(); - client_fmt = ipc_client_new(IPC_CLIENT_TYPE_FMT); + while(opt_i < argc) { + if(strncmp(argv[optind], "power-on", 8) == 0) { + ipc_client_power_on(client_fmt); + goto modem_quit; + } else if(strncmp(argv[optind], "power-off", 9) == 0) { + ipc_client_power_off(client_fmt); + goto modem_quit; + } else if (strncmp(argv[optind], "bootstrap", 9) == 0) { + ipc_client_create_handlers_common_data(client_fmt); + ipc_client_bootstrap_modem(client_fmt); + } else if(strncmp(argv[optind], "start", 5) == 0) { + printf("[0] Starting modem on FMT client\n"); + rc = modem_start(client_fmt); + if(rc < 0) { + printf("[E] Something went wrong\n"); + modem_stop(client_fmt); + return 1; + } - if (client_fmt == 0) { - printf("[E] Could not create IPC client; aborting ...\n"); - goto modem_quit; - } + printf("[1] Starting modem_read_loop on FMT client\n"); + modem_read_loop(client_fmt); - if (debug == 0) - ipc_client_set_log_handler(client_fmt, modem_log_handler_quiet, NULL); - else ipc_client_set_log_handler(client_fmt, modem_log_handler, NULL); - - while(opt_i < argc) { - if(strncmp(argv[optind], "power-on", 8) == 0) { - if (ipc_client_power_on(client_fmt) < 0) - printf("[E] Something went wrong while powering modem on\n"); - goto modem_quit; - } else if(strncmp(argv[optind], "power-off", 9) == 0) { - if (ipc_client_power_off(client_fmt) < 0) - printf("[E] Something went wrong while powering modem off\n"); - goto modem_quit; - } else if (strncmp(argv[optind], "bootstrap", 9) == 0) { - ipc_client_create_handlers_common_data(client_fmt); - ipc_client_bootstrap_modem(client_fmt); - } else if(strncmp(argv[optind], "start", 5) == 0) { - printf("[0] Starting modem on FMT client\n"); - rc = modem_start(client_fmt); - if(rc < 0) { - printf("[E] Something went wrong\n"); modem_stop(client_fmt); + } else { + printf("[E] Unknown argument: '%s'\n", argv[optind]); + print_help(); return 1; } - printf("[1] Starting modem_read_loop on FMT client\n"); - modem_read_loop(client_fmt); - - modem_stop(client_fmt); - } else { - printf("[E] Unknown argument: '%s'\n", argv[optind]); - print_help(); - return 1; + optind++; } - optind++; - } - modem_quit: - if (client_fmt != 0) - ipc_client_free(client_fmt); - ipc_shutdown(); + ipc_client_free(client_fmt); return 0; } -- cgit v1.1