diff options
author | Simon Busch <morphis@gravedo.de> | 2012-01-29 14:40:58 +0100 |
---|---|---|
committer | Simon Busch <morphis@gravedo.de> | 2012-02-03 17:39:56 +0100 |
commit | 3f3690d87ab76ff51f6197f1c4af4a30745ddcb2 (patch) | |
tree | f3fcb5b4e7d2a0937fabd51b8da30e6a01f820e5 | |
parent | 151efe36ffa69b841f7e9a6c4245015e2ab15657 (diff) | |
download | external_libsamsung-ipc-3f3690d87ab76ff51f6197f1c4af4a30745ddcb2.zip external_libsamsung-ipc-3f3690d87ab76ff51f6197f1c4af4a30745ddcb2.tar.gz external_libsamsung-ipc-3f3690d87ab76ff51f6197f1c4af4a30745ddcb2.tar.bz2 |
Rework device specific code so we can build one library for all devices now
Signed-off-by: Simon Busch <morphis@gravedo.de>
-rw-r--r-- | include/radio.h | 10 | ||||
-rw-r--r-- | samsung-ipc/Makefile.am | 5 | ||||
-rw-r--r-- | samsung-ipc/device/crespo/crespo_ipc.c | 12 | ||||
-rw-r--r-- | samsung-ipc/ipc.c | 39 | ||||
-rw-r--r-- | samsung-ipc/ipc_private.h | 14 | ||||
-rw-r--r-- | tools/modemctrl.c | 73 | ||||
-rw-r--r-- | vapi/samsung-ipc-1.0.vapi | 9 |
7 files changed, 104 insertions, 58 deletions
diff --git a/include/radio.h b/include/radio.h index 3decc07..bbb60af 100644 --- a/include/radio.h +++ b/include/radio.h @@ -26,8 +26,12 @@ #include "types.h" #include "util.h" -#define IPC_CLIENT_TYPE_FMT 0 -#define IPC_CLIENT_TYPE_RFS 1 +#define IPC_CLIENT_TYPE_FMT 0 +#define IPC_CLIENT_TYPE_RFS 1 + +#define IPC_DEVICE_CRESPO 0 + +#define IPC_DEVICE_MAX IPC_DEVICE_CRESPO #define IPC_COMMAND(f) ((f->group << 8) | f->index) #define IPC_GROUP(m) (m >> 8) @@ -59,7 +63,7 @@ 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); typedef int (*ipc_handler_cb)(void *io_data); -struct ipc_client *ipc_client_new(int client_type); +struct ipc_client *ipc_client_new(int device_type, int client_type); int ipc_client_free(struct ipc_client *client); int ipc_client_set_log_handler(struct ipc_client *client, ipc_client_log_handler_cb log_handler_cb, void *user_data); diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am index 46e4e6c..48b9265 100644 --- a/samsung-ipc/Makefile.am +++ b/samsung-ipc/Makefile.am @@ -27,11 +27,10 @@ libsamsung_ipc_la_SOURCES = \ call.c \ net.c \ sms.c \ - $(NULL) - -libsamsung_ipc_la_SOURCES += \ + \ device/crespo/crespo_ipc.c \ $(NULL) + AM_CFLAGS += -DDEVICE_IPC_V4 libsamsung_ipc_la_LIBADD = \ diff --git a/samsung-ipc/device/crespo/crespo_ipc.c b/samsung-ipc/device/crespo/crespo_ipc.c index 65f144d..9666a03 100644 --- a/samsung-ipc/device/crespo/crespo_ipc.c +++ b/samsung-ipc/device/crespo/crespo_ipc.c @@ -691,7 +691,7 @@ int crespo_ipc_common_data_get_fd(void *io_data) return (int) *(common_data); } -struct ipc_handlers ipc_default_handlers = { +struct ipc_handlers crespo_default_handlers = { .read = crespo_ipc_read, .write = crespo_ipc_write, .open = crespo_ipc_open, @@ -705,16 +705,22 @@ struct ipc_handlers ipc_default_handlers = { .common_data_get_fd = crespo_ipc_common_data_get_fd, }; -struct ipc_ops ipc_fmt_ops = { +struct ipc_ops crespo_fmt_ops = { .send = crespo_ipc_fmt_client_send, .recv = crespo_ipc_fmt_client_recv, .bootstrap = crespo_modem_bootstrap, }; -struct ipc_ops ipc_rfs_ops = { +struct ipc_ops crespo_rfs_ops = { .send = crespo_ipc_rfs_client_send, .recv = crespo_ipc_rfs_client_recv, .bootstrap = NULL, }; +void crespo_ipc_init(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/ipc.c b/samsung-ipc/ipc.c index f7fbb6d..c4384ff 100644 --- a/samsung-ipc/ipc.c +++ b/samsung-ipc/ipc.c @@ -29,15 +29,21 @@ #include "ipc_private.h" -extern struct ipc_ops ipc_fmt_ops; -extern struct ipc_ops ipc_rfs_ops; -extern struct ipc_handlers ipc_default_handlers; +struct ipc_device_desc devices[IPC_DEVICE_MAX+1]; 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); @@ -51,30 +57,31 @@ void ipc_client_log(struct ipc_client *client, const char *message, ...) va_end(args); } -struct ipc_client* ipc_client_new(int client_type) +struct ipc_client* ipc_client_new(int device_type, int client_type) { struct ipc_client *client; - struct ipc_ops *ops = NULL; + + if (device_type < 0 || device_type > IPC_DEVICE_MAX) + return 0; + if (client_type < 0 || client_type > IPC_CLIENT_TYPE_RFS) + return 0; + + client = (struct ipc_client*) malloc(sizeof(struct ipc_client)); + client->type = client_type; switch (client_type) { - case IPC_CLIENT_TYPE_FMT: - ops = &ipc_fmt_ops; - break; case IPC_CLIENT_TYPE_RFS: - ops = &ipc_rfs_ops; + client->ops = devices[device_type].rfs_ops; + break; + case IPC_CLIENT_TYPE_FMT: + client->ops = devices[device_type].fmt_ops; break; - default: - return NULL; } - client = (struct ipc_client*) malloc(sizeof(struct ipc_client)); - client->type = client_type; - client->ops = ops; client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers)); client->log_handler = log_handler_default; - - memcpy(client->handlers, &ipc_default_handlers, sizeof(struct ipc_handlers)); + memcpy(client->handlers, devices[device_type].handlers , sizeof(struct ipc_handlers)); return client; } diff --git a/samsung-ipc/ipc_private.h b/samsung-ipc/ipc_private.h index 5e374d0..1795def 100644 --- a/samsung-ipc/ipc_private.h +++ b/samsung-ipc/ipc_private.h @@ -23,10 +23,6 @@ #include <radio.h> -struct ipc_client; - -void ipc_client_log(struct ipc_client *client, const char *message, ...); - struct ipc_ops { int (*bootstrap)(struct ipc_client *client); int (*send)(struct ipc_client *client, struct ipc_message_info *); @@ -69,6 +65,16 @@ 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); + #endif // vim:ts=4:sw=4:expandtab diff --git a/tools/modemctrl.c b/tools/modemctrl.c index 5825ec7..14d996a 100644 --- a/tools/modemctrl.c +++ b/tools/modemctrl.c @@ -478,16 +478,19 @@ void print_help() printf("arguments:\n"); printf("\t--debug enable debug messages\n"); printf("\t--pin=[PIN] provide SIM card PIN\n"); + printf("\t--device=[NAME] name of device we're running on\n"); } 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 device_type = -1; struct option opt_l[] = { + {"device", required_argument, 0, 0 }, {"debug", no_argument, 0, 0 }, {"pin", required_argument, 0, 0 }, {0, 0, 0, 0 } @@ -498,9 +501,6 @@ 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) @@ -521,43 +521,60 @@ int main(int argc, char *argv[]) return 1; } } + } else if(strcmp(opt_l[opt_i].name, "device") == 0) { + if (optarg) { + if (strncmp(optarg, "crespo", 6) == 0) { + device_type = IPC_DEVICE_CRESPO; + } else { + printf("[E] Unknown device type!\n"); + return 1; + } + } } break; } } - 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 (device_type == -1) { + printf("[E] No device type given; aborting ...\n"); + return 1; + } - printf("[1] Starting modem_read_loop on FMT client\n"); - modem_read_loop(client_fmt); + client_fmt = ipc_client_new(device_type, IPC_CLIENT_TYPE_FMT); + ipc_client_set_log_handler(client_fmt, modem_log_handler_quiet, NULL); + 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); - } else { - printf("[E] Unknown argument: '%s'\n", argv[optind]); - print_help(); return 1; } - optind++; + 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++; + } + modem_quit: ipc_client_free(client_fmt); diff --git a/vapi/samsung-ipc-1.0.vapi b/vapi/samsung-ipc-1.0.vapi index bfc0929..6caa82f 100644 --- a/vapi/samsung-ipc-1.0.vapi +++ b/vapi/samsung-ipc-1.0.vapi @@ -29,6 +29,13 @@ namespace SamsungIpc RFS, } + [CCode (cname = "int", cprefix = "IPC_DEVICE_", has_type_id = false)] + public enum DeviceType + { + CRESPO, + H1, + } + [CCode (cname = "int", cprefix = "IPC_TYPE_", has_type_id = false)] public enum RequestType { @@ -1197,7 +1204,7 @@ namespace SamsungIpc [CCode (cname = "struct ipc_client", cprefix = "ipc_client_")] public class Client { - public Client(ClientType type); + public Client(DeviceType device_type, ClientType client_type); [CCode (delagate_target_pos = 0.9)] public int set_log_handler(LogHandlerCb log_cb); public int set_io_handlers(TransportCb write_cb, TransportCb read_cb); |