diff options
author | PaulK <contact@paulk.fr> | 2011-10-29 21:51:28 +0200 |
---|---|---|
committer | PaulK <contact@paulk.fr> | 2011-10-29 21:59:03 +0200 |
commit | 6f2a990c9920978ba895ce04dd1daeda8c75c11b (patch) | |
tree | 98b6df9ee5716ab7ddb75d0c8d953c528690a4d2 | |
parent | 4ab5a702c263d64e60ba9b50e40e2271f3e312d7 (diff) | |
download | external_libsamsung-ipc-6f2a990c9920978ba895ce04dd1daeda8c75c11b.zip external_libsamsung-ipc-6f2a990c9920978ba895ce04dd1daeda8c75c11b.tar.gz external_libsamsung-ipc-6f2a990c9920978ba895ce04dd1daeda8c75c11b.tar.bz2 |
New handlers structure (a data pointer for each handler function)
-rw-r--r-- | include/radio.h | 10 | ||||
-rw-r--r-- | samsung-ipc/device/crespo/crespo_ipc.c | 40 | ||||
-rw-r--r-- | samsung-ipc/device/crespo/crespo_ipc.h | 4 | ||||
-rw-r--r-- | samsung-ipc/device/h1/h1_ipc.c | 222 | ||||
-rw-r--r-- | samsung-ipc/ipc.c | 65 | ||||
-rw-r--r-- | samsung-ipc/ipc_private.h | 10 |
6 files changed, 179 insertions, 172 deletions
diff --git a/include/radio.h b/include/radio.h index 1614b98..17c01e2 100644 --- a/include/radio.h +++ b/include/radio.h @@ -54,7 +54,6 @@ struct ipc_handlers; typedef void (*ipc_client_log_handler_cb)(const char *message, void *user_data); -typedef void *(*ipc_handler_data_cb)(void); typedef int (*ipc_io_handler_cb)(void *data, unsigned int size, void *io_data); typedef int (*ipc_handler_cb)(void *data); @@ -64,11 +63,10 @@ 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, void *io_data, - ipc_io_handler_cb read, ipc_io_handler_cb write, - ipc_io_handler_cb open, ipc_io_handler_cb close); -void *ipc_client_get_handlers_io_data(struct ipc_client *client); -int ipc_client_set_handlers_io_data(struct ipc_client *client, void *io_data); +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_all_handlers_data(struct ipc_client *client, void *data); int ipc_client_bootstrap_modem(struct ipc_client *client); int ipc_client_open(struct ipc_client *client); diff --git a/samsung-ipc/device/crespo/crespo_ipc.c b/samsung-ipc/device/crespo/crespo_ipc.c index 61326da..44e31ca 100644 --- a/samsung-ipc/device/crespo/crespo_ipc.c +++ b/samsung-ipc/device/crespo/crespo_ipc.c @@ -318,27 +318,27 @@ int crespo_ipc_client_send(struct ipc_client *client, struct ipc_message_info *r assert(client->handlers->write != NULL); - rc = client->handlers->write((uint8_t*) &modem_data, sizeof(struct modem_io), client->handlers->io_data); + rc = client->handlers->write((uint8_t*) &modem_data, sizeof(struct modem_io), client->handlers->write_data); return rc; } -int wake_lock(char *lock_name, int size) +int wake_lock(char *lock_name) { int rc = 0; wake_lock_fd = open("/sys/power/wake_lock", O_RDWR); - rc = write(wake_lock_fd, lock_name, size); + rc = write(wake_lock_fd, lock_name, strlen(lock_name)); close(wake_lock_fd); return rc; } -int wake_unlock(char *lock_name, int size) +int wake_unlock(char *lock_name) { int rc = 0; wake_lock_fd = open("/sys/power/wake_unlock", O_RDWR); - rc = write(wake_unlock_fd, lock_name, size); + rc = write(wake_lock_fd, lock_name, strlen(lock_name)); close(wake_unlock_fd); return rc; @@ -356,10 +356,10 @@ int crespo_ipc_client_recv(struct ipc_client *client, struct ipc_message_info *r memset(response, 0, sizeof(struct ipc_message_info)); - wake_lock("secril_fmt-interface", sizeof("secril_fmt-interface") - 1); // FIXME sizeof("...") is ugly! + wake_lock("secril_fmt-interface"); assert(client->handlers->read != NULL); - bread = client->handlers->read((uint8_t*) &modem_data, sizeof(struct modem_io) + MAX_MODEM_DATA_SIZE, client->handlers->io_data); + bread = client->handlers->read((uint8_t*) &modem_data, sizeof(struct modem_io) + MAX_MODEM_DATA_SIZE, client->handlers->read_data); if (bread < 0) { ipc_client_log(client, "ERROR: crespo_ipc_client_recv: can't receive enough bytes from modem to process incoming response!"); @@ -397,7 +397,7 @@ int crespo_ipc_client_recv(struct ipc_client *client, struct ipc_message_info *r free(modem_data.data); - wake_unlock("secril_fmt-interface", sizeof("secril_fmt-interface") - 1); // FIXME sizeof("...") is ugly! + wake_unlock("secril_fmt-interface"); return 0; } @@ -411,11 +411,9 @@ int crespo_ipc_open(void *data, unsigned int size, void *io_data) { case IPC_CLIENT_TYPE_FMT: fd = open("/dev/modem_fmt", O_RDWR | O_NDELAY); - printf("crespo_ipc_open: opening /dev/modem_fmt\n"); break; case IPC_CLIENT_TYPE_RFS: fd = open("/dev/modem_rfs", O_RDWR | O_NDELAY); - printf("crespo_ipc_open: opening /dev/modem_rfs\n"); break; default: break; @@ -538,33 +536,11 @@ int crespo_ipc_power_off(void *data) return 0; } -void *crespo_ipc_io_data_reg(void) -{ - void *data = NULL; - - data = malloc(sizeof(int)); - - return data; -} - -int crespo_ipc_io_data_unreg(void *data) -{ - if(data == NULL) - return -1; - - free(data); - - return 0; -} - struct ipc_handlers ipc_default_handlers = { .read = crespo_ipc_read, .write = crespo_ipc_write, .open = crespo_ipc_open, .close = crespo_ipc_close, - .io_data_reg = crespo_ipc_io_data_reg, - .io_data_unreg = crespo_ipc_io_data_unreg, - .io_data = NULL, .power_on = crespo_ipc_power_on, .power_off = crespo_ipc_power_off, }; diff --git a/samsung-ipc/device/crespo/crespo_ipc.h b/samsung-ipc/device/crespo/crespo_ipc.h index 9edaa8a..d15bc23 100644 --- a/samsung-ipc/device/crespo/crespo_ipc.h +++ b/samsung-ipc/device/crespo/crespo_ipc.h @@ -42,8 +42,8 @@ struct samsung_rfs_cfrm void *mtd_read(char *mtd_name, int size, int block_size); void *file_read(char *file_name, int size, int block_size); -int wake_lock(char *lock_name, int size); -int wake_unlock(char *lock_name, int size); +int wake_lock(char *lock_name); +int wake_unlock(char *lock_name); extern struct ipc_handlers crespo_ipc_default_handlers; diff --git a/samsung-ipc/device/h1/h1_ipc.c b/samsung-ipc/device/h1/h1_ipc.c index b2065df..b281265 100644 --- a/samsung-ipc/device/h1/h1_ipc.c +++ b/samsung-ipc/device/h1/h1_ipc.c @@ -25,145 +25,190 @@ #include "ipc_private.h" #include "h1_ipc.h" -/* FIXME: move to io_data */ -static int fd = 0; - -int h1_ipc_open() +int h1_ipc_open(void *io_data) { - struct termios termios; + struct termios termios; + + int fd = -1; + + if(io_data == NULL) + return -1; - fd = open(DPRAM_TTY, O_RDWR); + fd = *((int *) io_data); - if(fd < 0) { - return 1; - } + fd = open(DPRAM_TTY, O_RDWR); - tcgetattr(fd, &termios); - cfmakeraw(&termios); - tcsetattr(fd, TCSANOW, &termios); + if(fd < 0) { + return 1; + } - return 0; + tcgetattr(fd, &termios); + cfmakeraw(&termios); + tcsetattr(fd, TCSANOW, &termios); + + return 0; } -int h1_ipc_close() +int h1_ipc_close(void *io_data) { - if(fd) { - return close(fd); - } + int fd = -1; + + if(io_data == NULL) + return -1; + + fd = *((int *) io_data); - return 0; + if(fd) { + return close(fd); + } + + return 0; } -int h1_ipc_power_on() +int h1_ipc_power_on(void *data) { - ioctl(fd, IOCTL_PHONE_ON); + int fd = -1; + + if(data == NULL) + return -1; + + fd = *((int *) data); - return 0; + ioctl(fd, IOCTL_PHONE_ON); + + return 0; } -int h1_ipc_power_off() +int h1_ipc_power_off(void *data) { - ioctl(fd, IOCTL_PHONE_OFF); + int fd = -1; + + if(data == NULL) + return -1; - return 0; + fd = *((int *) data); + + ioctl(fd, IOCTL_PHONE_OFF); + + return 0; } -int h1_ipc_send(struct ipc_client *client, struct ipc_message_info *request) +int h1_ipc_send(struct ipc_client *client, struct ipc_message_info *request) { - struct hdlc_header *hdlc; - unsigned char *frame; - unsigned char *payload; - int frame_length; + struct hdlc_header *hdlc; + unsigned char *frame; + unsigned char *payload; + int frame_length; - /* Frame length: HDLC/IPC header + payload length + HDLC flags (2) */ - frame_length = (sizeof(*hdlc) + request->length + 2); + /* Frame length: HDLC/IPC header + payload length + HDLC flags (2) */ + frame_length = (sizeof(*hdlc) + request->length + 2); - frame = (unsigned char*)malloc(frame_length); - frame[0] = FRAME_START; - frame[frame_length-1] = FRAME_END; + frame = (unsigned char*)malloc(frame_length); + frame[0] = FRAME_START; + frame[frame_length-1] = FRAME_END; - /* Setup HDLC header */ - hdlc = (struct hdlc_header*)(frame + 1); + /* Setup HDLC header */ + hdlc = (struct hdlc_header*)(frame + 1); - hdlc->length = (sizeof(*hdlc) + request->length); - hdlc->unknown = 0; + hdlc->length = (sizeof(*hdlc) + request->length); + hdlc->unknown = 0; - /* IPC header */ - hdlc->ipc.length = (sizeof(hdlc->ipc) + request->length); - hdlc->ipc.mseq = request->mseq; - hdlc->ipc.aseq = request->aseq; - hdlc->ipc.group = request->group; - hdlc->ipc.index = request->index; - hdlc->ipc.type = request->type; + /* IPC header */ + hdlc->ipc.length = (sizeof(hdlc->ipc) + request->length); + hdlc->ipc.mseq = request->mseq; + hdlc->ipc.aseq = request->aseq; + hdlc->ipc.group = request->group; + hdlc->ipc.index = request->index; + hdlc->ipc.type = request->type; - /* IPC payload */ - payload = (frame + 1 + sizeof(*hdlc)); - memcpy(payload, request->data, request->length); + /* IPC payload */ + payload = (frame + 1 + sizeof(*hdlc)); + memcpy(payload, request->data, request->length); - ipc_client_log(client, "sending %s %s\n", - ipc_command_type_to_str(IPC_COMMAND(request)), - ipc_response_type_to_str(request->type)); + ipc_client_log(client, "sending %s %s\n", + ipc_command_type_to_str(IPC_COMMAND(request)), + ipc_response_type_to_str(request->type)); - hex_dump(frame, frame_length); + hex_dump(frame, frame_length); - client->handlers->write(frame, frame_length, client->handlers->io_data); + client->handlers->write(frame, frame_length, client->handlers->io_data); - free(frame); + free(frame); - return 0; + return 0; } int h1_ipc_recv(struct ipc_client *client, struct ipc_message_info *response) { - unsigned char buf[4]; - unsigned char *data; - unsigned short *frame_length; - struct ipc_header *ipc; - int num_read; - int left; + unsigned char buf[4]; + unsigned char *data; + unsigned short *frame_length; + struct ipc_header *ipc; + int num_read; + int left; - num_read = client->handlers->read((void*)buf, sizeof(buf), client->handlers->io_data); + num_read = client->handlers->read((void*)buf, sizeof(buf), client->handlers->io_data); - if(num_read == sizeof(buf) && *buf == FRAME_START) { - frame_length = (unsigned short*)&buf[1]; - left = (*frame_length - 3 + 1); + if(num_read == sizeof(buf) && *buf == FRAME_START) { + frame_length = (unsigned short*)&buf[1]; + left = (*frame_length - 3 + 1); - data = (unsigned char*)malloc(left); - num_read = client->handlers->read((void*)data, left, client->handlers->io_data); + data = (unsigned char*)malloc(left); + num_read = client->handlers->read((void*)data, left, client->handlers->io_data); - if(num_read == left && data[left-1] == FRAME_END) { - ipc = (struct ipc_header*)data; - response->mseq = ipc->mseq; - response->aseq = ipc->aseq; - response->group = ipc->group; - response->index = ipc->index; - response->type = ipc->type; - response->length = (ipc->length - sizeof(*ipc)); + if(num_read == left && data[left-1] == FRAME_END) { + ipc = (struct ipc_header*)data; + response->mseq = ipc->mseq; + response->aseq = ipc->aseq; + response->group = ipc->group; + response->index = ipc->index; + response->type = ipc->type; + response->length = (ipc->length - sizeof(*ipc)); - response->data = (unsigned char*)malloc(response->length); - memcpy(response->data, (data + sizeof(*ipc)), response->length); + response->data = (unsigned char*)malloc(response->length); + memcpy(response->data, (data + sizeof(*ipc)), response->length); - ipc_client_log(client, "received %s %s\n", - ipc_command_type_to_str(IPC_COMMAND(response)), - ipc_response_type_to_str(response->type)); + ipc_client_log(client, "received %s %s\n", + ipc_command_type_to_str(IPC_COMMAND(response)), + ipc_response_type_to_str(response->type)); - hex_dump(data, num_read-1); + hex_dump(data, num_read-1); - return 0; - } - } + return 0; + } + } - return 0; + return 0; } int h1_ipc_read(void *data, unsigned int size, void *io_data) { - return read(fd, data, size); + int fd = -1; + + if(io_data == NULL) + return -1; + + fd = *((int *) io_data); + + if(fd < 0) + return -1; + + return read(fd, data, size); } int h1_ipc_write(void *data, unsigned int size, void *io_data) { - return write(fd, data, size); + int fd = -1; + + if(io_data == NULL) + return -1; + + fd = *((int *) io_data); + + if(fd < 0) + return -1; + + return write(fd, data, size); } struct ipc_handlers ipc_default_handlers = { @@ -173,9 +218,6 @@ struct ipc_handlers ipc_default_handlers = { .power_off = h1_ipc_power_off, .read = h1_ipc_read, .write = h1_ipc_write, - .io_data_reg = NULL, - .io_data_unreg = NULL, - .io_data = NULL, }; struct ipc_ops ipc_ops = { diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c index 213af4e..8b6ec96 100644 --- a/samsung-ipc/ipc.c +++ b/samsung-ipc/ipc.c @@ -79,8 +79,6 @@ struct ipc_client* ipc_client_new(int client_type) int ipc_client_free(struct ipc_client *client) { - if(client->handlers->io_data != NULL) - client->handlers->io_data_unreg(client->handlers->io_data); free(client->handlers); free(client); client = NULL; @@ -98,59 +96,50 @@ int ipc_client_set_log_handler(struct ipc_client *client, ipc_client_log_handler return 0; } -int ipc_client_set_io_handlers(struct ipc_client *client, void *io_data, - ipc_io_handler_cb read, ipc_io_handler_cb write, - ipc_io_handler_cb open, ipc_io_handler_cb close) +int ipc_client_set_handlers(struct ipc_client *client, struct ipc_handlers *handlers) { if(client == NULL) return -1; + if(handlers == NULL) + return -1; - if(read != NULL) - client->handlers->read = read; - if(write != NULL) - client->handlers->write = write; - if(open != NULL) - client->handlers->open = open; - if(close != NULL) - client->handlers->close = close; - if(io_data != NULL) - { - client->handlers->io_data = io_data; - if(client->handlers->io_data_reg != NULL) - client->handlers->io_data = client->handlers->io_data_reg(); - } + memcpy(client->handlers, handlers, sizeof(struct ipc_handlers)); return 0; } -int ipc_client_set_handlers(struct ipc_client *client, struct ipc_handlers *handlers) +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) { if(client == NULL) return -1; - if(handlers == NULL) - return -1; - - memcpy(client->handlers, handlers, sizeof(struct ipc_handlers)); - if(client->handlers->io_data_reg != NULL) - client->handlers->io_data = client->handlers->io_data_reg(); + if(read != NULL) + client->handlers->read = read; + if(read_data != NULL) + client->handlers->read_data = read_data; + if(write != NULL) + client->handlers->write = write; + if(write_data != NULL) + client->handlers->write_data = write_data; return 0; } -void *ipc_client_get_handlers_io_data(struct ipc_client *client) -{ - return client->handlers->io_data; -} - -int ipc_client_set_handlers_io_data(struct ipc_client *client, void *io_data) +int ipc_client_set_all_handlers_data(struct ipc_client *client, void *data) { if(client == NULL) return -1; - if(io_data == NULL) + if(data == NULL) return -1; - client->handlers->io_data=io_data; + client->handlers->read_data = data; + client->handlers->write_data = data; + client->handlers->open_data = data; + client->handlers->close_data = data; + client->handlers->power_on_data = data; + client->handlers->power_off_data = data; return 0; } @@ -177,7 +166,7 @@ int ipc_client_open(struct ipc_client *client) type = client->type; - return client->handlers->open(&type, 0, client->handlers->io_data); + return client->handlers->open(&type, 0, client->handlers->open_data); } int ipc_client_close(struct ipc_client *client) @@ -187,7 +176,7 @@ int ipc_client_close(struct ipc_client *client) client->handlers->open == NULL) return -1; - return client->handlers->close(NULL, 0, client->handlers->io_data); + return client->handlers->close(NULL, 0, client->handlers->close_data); } int ipc_client_power_on(struct ipc_client *client) @@ -197,7 +186,7 @@ int ipc_client_power_on(struct ipc_client *client) client->handlers->open == NULL) return -1; - return client->handlers->power_on(NULL); + return client->handlers->power_on(client->handlers->power_on_data); } int ipc_client_power_off(struct ipc_client *client) @@ -207,7 +196,7 @@ int ipc_client_power_off(struct ipc_client *client) client->handlers->open == NULL) return -1; - return client->handlers->power_off(NULL); + return client->handlers->power_off(client->handlers->power_off_data); } int _ipc_client_send(struct ipc_client *client, struct ipc_message_info *request) diff --git a/samsung-ipc/ipc_private.h b/samsung-ipc/ipc_private.h index 890889f..7c2787b 100644 --- a/samsung-ipc/ipc_private.h +++ b/samsung-ipc/ipc_private.h @@ -36,17 +36,19 @@ struct ipc_ops { struct ipc_handlers { /* Transport handlers/data */ ipc_io_handler_cb read; + void *read_data; ipc_io_handler_cb write; + void *write_data; ipc_io_handler_cb open; + void *open_data; ipc_io_handler_cb close; - - ipc_handler_data_cb io_data_reg; - ipc_handler_cb io_data_unreg; - void *io_data; + void *close_data; /* Power handlers */ ipc_handler_cb power_on; + void *power_on_data; ipc_handler_cb power_off; + void *power_off_data; }; struct ipc_client { |