diff options
-rw-r--r-- | include/radio.h | 8 | ||||
-rw-r--r-- | samsung-ipc/ipc.c | 59 | ||||
-rw-r--r-- | tools/modemctrl.c | 49 | ||||
-rw-r--r-- | vapi/samsung-ipc-1.0.vapi | 8 |
4 files changed, 93 insertions, 31 deletions
diff --git a/include/radio.h b/include/radio.h index bbb60af..a02297e 100644 --- a/include/radio.h +++ b/include/radio.h @@ -58,18 +58,22 @@ 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); typedef int (*ipc_handler_cb)(void *io_data); -struct ipc_client *ipc_client_new(int device_type, int client_type); +struct ipc_client* ipc_client_new(int client_type); +struct ipc_client *ipc_client_new_for_device(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); int ipc_client_set_handlers(struct ipc_client *client, struct ipc_handlers *handlers); -int ipc_client_set_io_handlers(struct ipc_client *client, +int ipc_client_set_io_handlers(struct ipc_client *client, ipc_io_handler_cb read, void *read_data, ipc_io_handler_cb write, void *write_data); int ipc_client_set_handlers_common_data(struct ipc_client *client, void *data); diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c index c4384ff..adc3816 100644 --- a/samsung-ipc/ipc.c +++ b/samsung-ipc/ipc.c @@ -23,7 +23,17 @@ #include <stdio.h> #include <string.h> #include <assert.h> +#include <stdint.h> #include <stdarg.h> +#include <unistd.h> +#include <stdbool.h> +#include <termios.h> +#include <fcntl.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <asm/types.h> #include <radio.h> @@ -31,6 +41,17 @@ struct ipc_device_desc devices[IPC_DEVICE_MAX+1]; +extern void crespo_ipc_init(void); + +void ipc_init(void) +{ + crespo_ipc_init(); +} + +void ipc_shutdown(void) +{ +} + void log_handler_default(const char *message, void *user_data) { printf("%s\n", message); @@ -57,7 +78,37 @@ void ipc_client_log(struct ipc_client *client, const char *message, ...) va_end(args); } -struct ipc_client* ipc_client_new(int device_type, int client_type) +struct ipc_client* ipc_client_new(int client_type) +{ + int device_type = -1, in_hardware = 0; + char buf[4096]; + + // gather device type from /proc/cpuinfo + int fd = open("/proc/cpuinfo", O_RDONLY); + int bytesread = read(fd, buf, 4096); + close(fd); + + // match hardware name with our supported devices + char *pch = strtok(buf, "\n"); + while (pch != NULL) + { + int rc; + if ((rc = strncmp(pch, "Hardware", 9)) == 9) + { + if (strstr(pch, "herring") != NULL) + device_type = IPC_DEVICE_CRESPO; + } + pch = strtok(NULL, "\n"); + } + + // validate that we have found any supported device + if (device_type == -1) + return NULL; + + return ipc_client_new_for_device(device_type, client_type); +} + +struct ipc_client* ipc_client_new_for_device(int device_type, int client_type) { struct ipc_client *client; @@ -81,7 +132,8 @@ struct ipc_client* ipc_client_new(int device_type, int client_type) client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers)); client->log_handler = log_handler_default; - memcpy(client->handlers, devices[device_type].handlers , sizeof(struct ipc_handlers)); + if (devices[device_type].handlers != 0) + memcpy(client->handlers, devices[device_type].handlers , sizeof(struct ipc_handlers)); return client; } @@ -91,7 +143,6 @@ int ipc_client_free(struct ipc_client *client) free(client->handlers); free(client); client = NULL; - return 0; } @@ -117,7 +168,7 @@ int ipc_client_set_handlers(struct ipc_client *client, struct ipc_handlers *hand return 0; } -int ipc_client_set_io_handlers(struct ipc_client *client, +int ipc_client_set_io_handlers(struct ipc_client *client, ipc_io_handler_cb read, void *read_data, ipc_io_handler_cb write, void *write_data) { diff --git a/tools/modemctrl.c b/tools/modemctrl.c index 14d996a..d96a751 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) @@ -478,7 +478,6 @@ 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[]) @@ -487,10 +486,10 @@ int main(int argc, char *argv[]) int c = 0; int opt_i = 0; int rc = -1; - int device_type = -1; + int debug = 0; struct option opt_l[] = { - {"device", required_argument, 0, 0 }, + {"help", no_argument, 0, 0 }, {"debug", no_argument, 0, 0 }, {"pin", required_argument, 0, 0 }, {0, 0, 0, 0 } @@ -508,8 +507,11 @@ int main(int argc, char *argv[]) switch(c) { case 0: - if(strcmp(opt_l[opt_i].name, "debug") == 0) { - ipc_client_set_log_handler(client_fmt, modem_log_handler, NULL); + 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; printf("[I] Debug enabled\n"); } else if(strcmp(opt_l[opt_i].name, "pin") == 0) { if(optarg) { @@ -521,34 +523,31 @@ 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; } } - if (device_type == -1) { - printf("[E] No device type given; aborting ...\n"); - return 1; + ipc_init(); + client_fmt = ipc_client_new(IPC_CLIENT_TYPE_FMT); + + if (client_fmt == 0) { + printf("[E] Could not create IPC client; aborting ...\n"); + goto modem_quit; } - client_fmt = ipc_client_new(device_type, IPC_CLIENT_TYPE_FMT); - ipc_client_set_log_handler(client_fmt, modem_log_handler_quiet, NULL); + 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) { - ipc_client_power_on(client_fmt); + 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) { - ipc_client_power_off(client_fmt); + 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); @@ -576,7 +575,9 @@ int main(int argc, char *argv[]) } modem_quit: - ipc_client_free(client_fmt); + if (client_fmt != 0) + ipc_client_free(client_fmt); + ipc_shutdown(); return 0; } diff --git a/vapi/samsung-ipc-1.0.vapi b/vapi/samsung-ipc-1.0.vapi index 6caa82f..ebef347 100644 --- a/vapi/samsung-ipc-1.0.vapi +++ b/vapi/samsung-ipc-1.0.vapi @@ -1200,11 +1200,17 @@ namespace SamsungIpc public delegate int TransportCb(uint8[] data); public delegate void LogHandlerCb(string message); + [CCode (cname = "ipc_init")] + public void init(); + [CCode (cname = "ipc_shutdown")] + public void shutdown(); + [Compact] [CCode (cname = "struct ipc_client", cprefix = "ipc_client_")] public class Client { - public Client(DeviceType device_type, ClientType client_type); + public Client(ClientType client_type); + public Client.for_device(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); |