diff options
author | Joerie de Gram <j.de.gram@gmail.com> | 2011-08-17 23:00:35 +0200 |
---|---|---|
committer | Joerie de Gram <j.de.gram@gmail.com> | 2011-08-17 23:00:35 +0200 |
commit | 7bb4a47d77b7c09319a82c42948c6b385fd3b81d (patch) | |
tree | 45c5c83de2b402458f2ccceee81cbdd88e001931 | |
parent | 4dea3cd4bbc899a88715b752e8201a4ee9e5b65b (diff) | |
download | external_libsamsung-ipc-7bb4a47d77b7c09319a82c42948c6b385fd3b81d.zip external_libsamsung-ipc-7bb4a47d77b7c09319a82c42948c6b385fd3b81d.tar.gz external_libsamsung-ipc-7bb4a47d77b7c09319a82c42948c6b385fd3b81d.tar.bz2 |
Massive cleanup & device specific frame handling
- Introduced device specific frame handling
- Removed all IPC command helper functions
- General cleanup
-rw-r--r-- | Android.mk | 25 | ||||
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | call.c | 59 | ||||
-rw-r--r-- | hexdump.c | 87 | ||||
-rw-r--r-- | include/gen.h (renamed from hexdump.h) | 13 | ||||
-rw-r--r-- | include/radio.h | 171 | ||||
-rw-r--r-- | include/types.h | 127 | ||||
-rw-r--r-- | include/util.h | 1 | ||||
-rw-r--r-- | ipc.c (renamed from sms.c) | 32 | ||||
-rw-r--r-- | ipc_util.c | 151 | ||||
-rw-r--r-- | misc.c | 70 | ||||
-rw-r--r-- | net.c | 83 | ||||
-rw-r--r-- | radio.c | 345 | ||||
-rw-r--r-- | radio_internal.h | 62 | ||||
-rw-r--r-- | sim.c | 47 | ||||
-rw-r--r-- | test.c | 62 | ||||
-rw-r--r-- | util.c | 3 |
17 files changed, 425 insertions, 923 deletions
@@ -2,20 +2,29 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) libsamsung-ipc_files := \ - radio.c \ + ipc.c \ + ipc_util.c \ util.c \ - hexdump.c \ - call.c \ - sim.c \ - sms.c \ - net.c \ - misc.c + devices/$(TARGET_DEVICE)/ipc.c LOCAL_MODULE := libsamsung-ipc LOCAL_MODULE_TAGS := optional LOCAL_C_INCLUDES := $(LOCAL_PATH)/include - LOCAL_SRC_FILES := $(libsamsung-ipc_files) + include $(BUILD_STATIC_LIBRARY) +include $(CLEAR_VARS) + +LOCAL_MODULE := ipc-test +LOCAL_MODULE_TAGS := optional + +LOCAL_SHARED_LIBRARIES := libutils + +LOCAL_CFLAGS := -DLOG_STDOUT +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include +LOCAL_SRC_FILES := $(libsamsung-ipc_files) test.c + +include $(BUILD_EXECUTABLE) + diff --git a/Makefile b/Makefile deleted file mode 100644 index 0d2234c..0000000 --- a/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CROSS_COMPILE ?= arm-none-linux-gnueabi- - -all: lib test - -lib: - $(CROSS_COMPILE)gcc -Iinclude -shared radio.c hexdump.c -o libsamsung-ipc.so - -test: - $(CROSS_COMPILE)gcc -shared -Iinclude test.c -L. -lsamsung-ipc -lpthread -o ipc-test - @@ -1,59 +0,0 @@ -/** - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -#include <call.h> -#include "radio_internal.h" - -void ipc_call_outgoing(const char *number, int identity, int request_id) -{ - struct ipc_call_outgoing call; - - memset(&call, 0x00, sizeof(call)); - - if(strlen(number) > 82) { - printf("Outgoing call number too long\n"); - return; - } - - call.type = IPC_CALL_TYPE_VOICE; - call.identity = identity; - call.prefix = IPC_CALL_PREFIX_NONE; - - call.length = strlen(number); - memcpy(call.number, number, strlen(number)); - - ipc_send(IPC_CALL_OUTGOING, IPC_TYPE_EXEC, (unsigned char*)&call, sizeof(call), request_id); -} - -void ipc_call_release(int request_id) -{ - ipc_send_exec(IPC_CALL_RELEASE, request_id); -} - -void ipc_call_answer(int request_id) -{ - ipc_send_exec(IPC_CALL_ANSWER, request_id); -} - -void ipc_call_list(int request_id) -{ - ipc_send_get(IPC_CALL_LIST, request_id); -} - diff --git a/hexdump.c b/hexdump.c deleted file mode 100644 index 93250b8..0000000 --- a/hexdump.c +++ /dev/null @@ -1,87 +0,0 @@ -/** - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include "hexdump.h" - -#ifdef ANDROID - -#define LOG_TAG "RIL" -#include <utils/Log.h> -#define printf LOGI - -#endif - -void hex_dump(void *data, int size) -{ - /* dumps size bytes of *data to stdout. Looks like: - * [0000] 75 6E 6B 6E 6F 77 6E 20 - * 30 FF 00 00 00 00 39 00 unknown 0.....9. - * (in a single line of course) - */ - - unsigned char *p = data; - unsigned char c; - int n; - char bytestr[4] = {0}; - char addrstr[10] = {0}; - char hexstr[ 16*3 + 5] = {0}; - char charstr[16*1 + 5] = {0}; - for(n=1;n<=size;n++) { - if (n%16 == 1) { - /* store address for this line */ - snprintf(addrstr, sizeof(addrstr), "%.4x", - ((unsigned int)p-(unsigned int)data) ); - } - - c = *p; - if (isalnum(c) == 0) { - c = '.'; - } - - /* store hex str (for left side) */ - snprintf(bytestr, sizeof(bytestr), "%02X ", *p); - strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); - - /* store char str (for right side) */ - snprintf(bytestr, sizeof(bytestr), "%c", c); - strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); - - if(n%16 == 0) { - /* line completed */ - printf("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); - hexstr[0] = 0; - charstr[0] = 0; - } else if(n%8 == 0) { - /* half line: add whitespaces */ - strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); - strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); - } - p++; /* next byte */ - } - - if (strlen(hexstr) > 0) { - /* print rest of buffer if not empty */ - printf("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); - } -} - diff --git a/hexdump.h b/include/gen.h index 152bf7f..4b6b7bd 100644 --- a/hexdump.h +++ b/include/gen.h @@ -18,5 +18,16 @@ * */ -void hex_dump(void *data, int size); +#ifndef __GEN_H__ +#define __GEN_H__ + +#define IPC_GEN_PHONE_RES 0x8001 + +struct ipc_gen_phone_res { + unsigned char group, type; + unsigned short code; + unsigned char unk; +} __attribute__((__packed__)); + +#endif diff --git a/include/radio.h b/include/radio.h index d426f59..cfefe2f 100644 --- a/include/radio.h +++ b/include/radio.h @@ -21,148 +21,53 @@ #ifndef __RADIO_H__ #define __RADIO_H__ -#include "call.h" -#include "disp.h" -#include "misc.h" -#include "net.h" -#include "sec.h" -#include "sms.h" - -/* AP -> Baseband */ -#define IPC_TYPE_EXEC 0x01 -#define IPC_TYPE_GET 0x02 -#define IPC_TYPE_SET 0x03 -#define IPC_TYPE_CFRM 0x04 -#define IPC_TYPE_EVENT 0x05 - -/* Baseband -> AP */ -#define IPC_TYPE_INDI 0x01 -#define IPC_TYPE_RESP 0x02 -#define IPC_TYPE_NOTI 0x03 - -/* Message groups */ -#define IPC_GROUP_PWR 0x01 -#define IPC_GROUP_CALL 0x02 -#define IPC_GROUP_SMS 0x04 -#define IPC_GROUP_SEC 0x05 -#define IPC_GROUP_PB 0x06 -#define IPC_GROUP_DISP 0x07 -#define IPC_GROUP_NET 0x08 -#define IPC_GROUP_SND 0x09 -#define IPC_GROUP_MISC 0x0A -#define IPC_GROUP_SVC 0x0B -#define IPC_GROUP_SS 0x0C -#define IPC_GROUP_GPRS 0x0D -#define IPC_GROUP_SAT 0x0E -#define IPC_GROUP_CFG 0x0F -#define IPC_GROUP_IMEI 0x10 -#define IPC_GROUP_GPS 0x11 -#define IPC_GROUP_SAP 0x12 -#define IPC_GROUP_GEN 0x80 - -/* Power */ -#define IPC_PWR_PHONE_PWR_UP 0x0101 -#define IPC_PWR_PHONE_PWR_OFF 0x0102 -#define IPC_PWR_PHONE_RESET 0x0103 -#define IPC_PWR_BATT_STATUS 0x0104 -#define IPC_PWR_BATT_TYPE 0x0105 -#define IPC_PWR_BATT_COMP 0x0106 -#define IPC_PWR_PHONE_ONLINE 0x0107 - -/* Pb */ -#define IPC_PB_ACCESS 0x0601 -#define IPC_PB_STORAGE 0x0602 -#define IPC_PB_STORAGE_LIST 0x0603 -#define IPC_PB_ENTRY_INFO 0x0604 -#define IPC_PB_CAPABILITY_INFO 0x0605 - -/* SS */ -#define IPC_SS_WAITING 0x0C01 -#define IPC_SS_CLI 0x0C02 -#define IPC_SS_BARRING 0x0C03 -#define IPC_SS_BARRING_PW 0x0C04 -#define IPC_SS_FORWARDING 0x0C05 -#define IPC_SS_INFO 0x0C06 -#define IPC_SS_MANAGE_CALL 0x0C07 -#define IPC_SS_USSD 0x0C08 -#define IPC_SS_AOC 0x0C09 -#define IPC_SS_RELEASE_COMPLETE 0x0C0A - -/* GPRS */ -#define IPC_GPRS_DEFINE_PDP_CONTEXT 0x0D01 -#define IPC_GPRS_QOS 0x0D02 -#define IPC_GPRS_PS 0x0D03 -#define IPC_GPRS_PDP_CONTEXT 0x0D04 -#define IPC_GPRS_SHOW_PDP_ADDR 0x0D05 -#define IPC_GPRS_MS_CLASS 0x0D06 -#define IPC_GPRS_3G_QUAL_SERVICE_PROFILE 0x0D07 -#define IPC_GPRS_IP_CONFIGURATION 0x0D08 -#define IPC_GPRS_DEFINE_SEC_PDP_CONTEXT 0x0D09 -#define IPC_GPRS_TFT 0x0D0A -#define IPC_GPRS_HSDPA_STATUS 0x0D0B -#define IPC_GPRS_CURRENT_SESSION_DATA_COUNT 0x0D0C -#define IPC_GPRS_DATA_DORMANT 0x0D0D -#define IPC_GPRS_DUN_PIN_CTRL 0x0D0E -#define IPC_GPRS_CALL_STATUS 0x0D0F - -/* Sat */ -#define IPC_SAT_PROFILE_DOWNLOAD 0x0E01 -#define IPC_SAT_ENVELOPE_CMD 0x0E02 -#define IPC_SAT_PROACTIVE_CMD 0x0E03 -#define IPC_SAT_TERMINATE_USAT_SESSION 0x0E04 -#define IPC_SAT_EVENT_DOWNLOAD 0x0E05 -#define IPC_SAT_PROVIDE_LOCAL_INFO 0x0E06 -#define IPC_SAT_POLLING 0x0E07 -#define IPC_SAT_REFRESH 0x0E08 -#define IPC_SAT_SETUP_EVENT_LIST 0x0E09 -#define IPC_SAT_CALL_CONTROL_RESULT 0x0E0A -#define IPC_SAT_IMAGE_CLUT 0x0E0B -#define IPC_SAT_CALL_PROCESSING 0x0E0C - -/* IMEI */ -#define IPC_IMEI_START 0x1001 -#define IPC_IMEI_CHECK_DEVICE_INFO 0x1002 - -/* Gen */ -#define IPC_GEN_PHONE_RES 0x8001 - -#define FRAME_START 0x7f -#define FRAME_END 0x7e - -#define FRAME_ID(f) ((f->group << 8) | f->index) -#define FRAME_GRP(m) (m >> 8) -#define FRAME_IDX(m) (m & 0xff) -#define FRAME_STR(f) case f: return #f; - -#define SWAP16(x) ((x >> 8) | ((x & 0xff) << 8)) +#include "types.h" +#include "util.h" + +#define IPC_COMMAND(f) ((f->group << 8) | f->index) +#define IPC_GROUP(m) (m >> 8) +#define IPC_INDEX(m) (m & 0xff) + +/* IPC header for use by device specific code*/ +struct ipc_header { + unsigned short length; + unsigned char mseq, aseq; + unsigned char group, index, type; +} __attribute__((__packed__)); -struct ipc_request_info { - unsigned short type; - unsigned char method; - unsigned char id; - void *data; - int length; +/* Request struct passed as parameter to ipc_send() */ +struct ipc_request { + unsigned char mseq, aseq, group, index, type; + unsigned int length; + unsigned char *data; }; -struct ipc_info { - char *tty; - void (*on_receive)(struct ipc_request_info *info); +/* Response struct returned by ipc_recv() */ +struct ipc_response { + unsigned char mseq, aseq; + unsigned short command; + unsigned char type; + unsigned int data_length; + unsigned char *data; }; -struct ipc_gen_phone_res { - unsigned char group, type; - unsigned short code; - unsigned char unk; -} __attribute__((__packed__)); +int ipc_open(); +int ipc_close(); -void ipc_register(struct ipc_info *ipc); -void ipc_open(); -void ipc_close(); void ipc_power_on(); void ipc_power_off(); -void ipc_loop(); -void ipc_send(const int type, const int method, const unsigned char *data, const int data_length, int request_id); +void ipc_send(struct ipc_request *request); +int ipc_recv(struct ipc_response *response); + +/* Convenience functions for ipc_send */ +void ipc_msg_send(const int command, const int type, unsigned char *data, const int length, unsigned char aseq); +void ipc_msg_send_get(const int command, unsigned char aseq); +void ipc_msg_send_exec(const int command, unsigned char aseq); + +/* Utility functions */ +const char *ipc_str(struct ipc_response *frame); +const char *ipc_response_type(struct ipc_response *frame); #endif diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..3a9f714 --- /dev/null +++ b/include/types.h @@ -0,0 +1,127 @@ +/** + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __TYPES_H__ +#define __TYPES_H__ + +#include "call.h" +#include "disp.h" +#include "gen.h" +#include "misc.h" +#include "net.h" +#include "sec.h" +#include "sms.h" + +/* AP -> Baseband */ +#define IPC_TYPE_EXEC 0x01 +#define IPC_TYPE_GET 0x02 +#define IPC_TYPE_SET 0x03 +#define IPC_TYPE_CFRM 0x04 +#define IPC_TYPE_EVENT 0x05 + +/* Baseband -> AP */ +#define IPC_TYPE_INDI 0x01 +#define IPC_TYPE_RESP 0x02 +#define IPC_TYPE_NOTI 0x03 + +/* Message groups */ +#define IPC_GROUP_PWR 0x01 +#define IPC_GROUP_CALL 0x02 +#define IPC_GROUP_SMS 0x04 +#define IPC_GROUP_SEC 0x05 +#define IPC_GROUP_PB 0x06 +#define IPC_GROUP_DISP 0x07 +#define IPC_GROUP_NET 0x08 +#define IPC_GROUP_SND 0x09 +#define IPC_GROUP_MISC 0x0A +#define IPC_GROUP_SVC 0x0B +#define IPC_GROUP_SS 0x0C +#define IPC_GROUP_GPRS 0x0D +#define IPC_GROUP_SAT 0x0E +#define IPC_GROUP_CFG 0x0F +#define IPC_GROUP_IMEI 0x10 +#define IPC_GROUP_GPS 0x11 +#define IPC_GROUP_SAP 0x12 +#define IPC_GROUP_GEN 0x80 + +/* Power */ +#define IPC_PWR_PHONE_PWR_UP 0x0101 +#define IPC_PWR_PHONE_PWR_OFF 0x0102 +#define IPC_PWR_PHONE_RESET 0x0103 +#define IPC_PWR_BATT_STATUS 0x0104 +#define IPC_PWR_BATT_TYPE 0x0105 +#define IPC_PWR_BATT_COMP 0x0106 +#define IPC_PWR_PHONE_ONLINE 0x0107 + +/* Pb */ +#define IPC_PB_ACCESS 0x0601 +#define IPC_PB_STORAGE 0x0602 +#define IPC_PB_STORAGE_LIST 0x0603 +#define IPC_PB_ENTRY_INFO 0x0604 +#define IPC_PB_CAPABILITY_INFO 0x0605 + +/* SS */ +#define IPC_SS_WAITING 0x0C01 +#define IPC_SS_CLI 0x0C02 +#define IPC_SS_BARRING 0x0C03 +#define IPC_SS_BARRING_PW 0x0C04 +#define IPC_SS_FORWARDING 0x0C05 +#define IPC_SS_INFO 0x0C06 +#define IPC_SS_MANAGE_CALL 0x0C07 +#define IPC_SS_USSD 0x0C08 +#define IPC_SS_AOC 0x0C09 +#define IPC_SS_RELEASE_COMPLETE 0x0C0A + +/* GPRS */ +#define IPC_GPRS_DEFINE_PDP_CONTEXT 0x0D01 +#define IPC_GPRS_QOS 0x0D02 +#define IPC_GPRS_PS 0x0D03 +#define IPC_GPRS_PDP_CONTEXT 0x0D04 +#define IPC_GPRS_SHOW_PDP_ADDR 0x0D05 +#define IPC_GPRS_MS_CLASS 0x0D06 +#define IPC_GPRS_3G_QUAL_SERVICE_PROFILE 0x0D07 +#define IPC_GPRS_IP_CONFIGURATION 0x0D08 +#define IPC_GPRS_DEFINE_SEC_PDP_CONTEXT 0x0D09 +#define IPC_GPRS_TFT 0x0D0A +#define IPC_GPRS_HSDPA_STATUS 0x0D0B +#define IPC_GPRS_CURRENT_SESSION_DATA_COUNT 0x0D0C +#define IPC_GPRS_DATA_DORMANT 0x0D0D +#define IPC_GPRS_DUN_PIN_CTRL 0x0D0E +#define IPC_GPRS_CALL_STATUS 0x0D0F + +/* Sat */ +#define IPC_SAT_PROFILE_DOWNLOAD 0x0E01 +#define IPC_SAT_ENVELOPE_CMD 0x0E02 +#define IPC_SAT_PROACTIVE_CMD 0x0E03 +#define IPC_SAT_TERMINATE_USAT_SESSION 0x0E04 +#define IPC_SAT_EVENT_DOWNLOAD 0x0E05 +#define IPC_SAT_PROVIDE_LOCAL_INFO 0x0E06 +#define IPC_SAT_POLLING 0x0E07 +#define IPC_SAT_REFRESH 0x0E08 +#define IPC_SAT_SETUP_EVENT_LIST 0x0E09 +#define IPC_SAT_CALL_CONTROL_RESULT 0x0E0A +#define IPC_SAT_IMAGE_CLUT 0x0E0B +#define IPC_SAT_CALL_PROCESSING 0x0E0C + +/* IMEI */ +#define IPC_IMEI_START 0x1001 +#define IPC_IMEI_CHECK_DEVICE_INFO 0x1002 + +#endif diff --git a/include/util.h b/include/util.h index 8f3b5f9..68426ab 100644 --- a/include/util.h +++ b/include/util.h @@ -18,6 +18,7 @@ * */ +void hex_dump(void *data, int size); const char *plmn_lookup(const char *plmn); char *plmn_string(const char *plmn); @@ -18,16 +18,36 @@ * */ -#include "radio_internal.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> -void ipc_sms_send_msg(unsigned char *data, unsigned char length, int request_id) +#include <radio.h> + +/* Convenience functions for ipc_send */ +inline void ipc_msg_send_get(const int command, unsigned char aseq) +{ + ipc_msg_send(command, IPC_TYPE_GET, 0, 0, aseq); +} + +inline void ipc_msg_send_exec(const int command, unsigned char aseq) { - ipc_send(IPC_SMS_SEND_MSG, IPC_TYPE_EXEC, data, length, request_id); + ipc_msg_send(command, IPC_TYPE_EXEC, 0, 0, aseq); } -void ipc_sms_deliver_report(int request_id) +/* Wrapper for ipc_send */ +void ipc_msg_send(const int command, const int type, unsigned char *data, const int length, unsigned char aseq) { - unsigned char data[247] = { 0x00, 0x00, 0x03, 0x00, 0x02 }; - ipc_send(IPC_SMS_DELIVER_REPORT, IPC_TYPE_EXEC, data, sizeof(data), request_id); + struct ipc_request request; + + request.mseq = 0xff; + request.aseq = aseq; + request.group = IPC_GROUP(command); + request.index = IPC_INDEX(command); + request.type = type; + request.length = length; + request.data = data; + + ipc_send(&request); } diff --git a/ipc_util.c b/ipc_util.c new file mode 100644 index 0000000..d497f2f --- /dev/null +++ b/ipc_util.c @@ -0,0 +1,151 @@ +/** + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + * + */ + +#include <radio.h> + +#define IPC_STR(f) case f: return #f; + +const char *ipc_response_type(struct ipc_response *frame) { + switch(frame->type) { + case IPC_TYPE_INDI: + return "INDI"; + case IPC_TYPE_RESP: + return "RESP"; + case IPC_TYPE_NOTI: + return "NOTI"; + default: + return "UNKNOWN"; + } +} + +const char *ipc_str(struct ipc_response *frame) { + switch(frame->command) { + IPC_STR(IPC_PWR_PHONE_PWR_UP) + IPC_STR(IPC_PWR_PHONE_PWR_OFF) + IPC_STR(IPC_PWR_PHONE_RESET) + IPC_STR(IPC_PWR_BATT_STATUS) + IPC_STR(IPC_PWR_BATT_TYPE) + IPC_STR(IPC_PWR_BATT_COMP) + IPC_STR(IPC_PWR_PHONE_ONLINE) + IPC_STR(IPC_CALL_OUTGOING) + IPC_STR(IPC_CALL_INCOMING) + IPC_STR(IPC_CALL_RELEASE) + IPC_STR(IPC_CALL_ANSWER) + IPC_STR(IPC_CALL_STATUS) + IPC_STR(IPC_CALL_LIST) + IPC_STR(IPC_CALL_BURST_DTMF) + IPC_STR(IPC_CALL_CONT_DTMF) + IPC_STR(IPC_CALL_WAITING) + IPC_STR(IPC_CALL_LINE_ID) + IPC_STR(IPC_SMS_SEND_MSG) + IPC_STR(IPC_SMS_INCOMING_MSG) + IPC_STR(IPC_SMS_READ_MSG) + IPC_STR(IPC_SMS_SAVE_MSG) + IPC_STR(IPC_SMS_DEL_MSG) + IPC_STR(IPC_SMS_DELIVER_REPORT) + IPC_STR(IPC_SMS_DEVICE_READY) + IPC_STR(IPC_SMS_SEL_MEM) + IPC_STR(IPC_SMS_STORED_MSG_COUNT) + IPC_STR(IPC_SMS_SVC_CENTER_ADDR) + IPC_STR(IPC_SMS_SVC_OPTION) + IPC_STR(IPC_SMS_MEM_STATUS) + IPC_STR(IPC_SMS_CBS_MSG) + IPC_STR(IPC_SMS_CBS_CONFIG) + IPC_STR(IPC_SMS_STORED_MSG_STATUS) + IPC_STR(IPC_SMS_PARAM_COUNT) + IPC_STR(IPC_SMS_PARAM) + IPC_STR(IPC_SEC_PIN_STATUS) + IPC_STR(IPC_SEC_PHONE_LOCK) + IPC_STR(IPC_SEC_CHANGE_LOCKING_PW) + IPC_STR(IPC_SEC_SIM_LANG) + IPC_STR(IPC_SEC_RSIM_ACCESS) + IPC_STR(IPC_SEC_GSIM_ACCESS) + IPC_STR(IPC_SEC_SIM_ICC_TYPE) + IPC_STR(IPC_SEC_LOCK_INFO) + IPC_STR(IPC_SEC_ISIM_AUTH) + IPC_STR(IPC_PB_ACCESS) + IPC_STR(IPC_PB_STORAGE) + IPC_STR(IPC_PB_STORAGE_LIST) + IPC_STR(IPC_PB_ENTRY_INFO) + IPC_STR(IPC_PB_CAPABILITY_INFO) + IPC_STR(IPC_DISP_ICON_INFO) + IPC_STR(IPC_DISP_HOMEZONE_INFO) + IPC_STR(IPC_NET_PREF_PLMN) + IPC_STR(IPC_NET_PLMN_SEL) + IPC_STR(IPC_NET_CURRENT_PLMN) + IPC_STR(IPC_NET_PLMN_LIST) + IPC_STR(IPC_NET_REGIST) + IPC_STR(IPC_NET_SUBSCRIBER_NUM) + IPC_STR(IPC_NET_BAND_SEL) + IPC_STR(IPC_NET_SERVICE_DOMAIN_CONFIG) + IPC_STR(IPC_NET_POWERON_ATTACH) + IPC_STR(IPC_NET_MODE_SEL) + IPC_STR(IPC_NET_ACQ_ORDER) + IPC_STR(IPC_NET_IDENTITY) + IPC_STR(IPC_NET_CURRENT_RRC_STATUS) + IPC_STR(IPC_MISC_ME_VERSION) + IPC_STR(IPC_MISC_ME_IMSI) + IPC_STR(IPC_MISC_ME_SN) + IPC_STR(IPC_MISC_TIME_INFO) + IPC_STR(IPC_SS_WAITING) + IPC_STR(IPC_SS_CLI) + IPC_STR(IPC_SS_BARRING) + IPC_STR(IPC_SS_BARRING_PW) + IPC_STR(IPC_SS_FORWARDING) + IPC_STR(IPC_SS_INFO) + IPC_STR(IPC_SS_MANAGE_CALL) + IPC_STR(IPC_SS_USSD) + IPC_STR(IPC_SS_AOC) + IPC_STR(IPC_SS_RELEASE_COMPLETE) + IPC_STR(IPC_GPRS_DEFINE_PDP_CONTEXT) + IPC_STR(IPC_GPRS_QOS) + IPC_STR(IPC_GPRS_PS) + IPC_STR(IPC_GPRS_PDP_CONTEXT) + IPC_STR(IPC_GPRS_SHOW_PDP_ADDR) + IPC_STR(IPC_GPRS_MS_CLASS) + IPC_STR(IPC_GPRS_3G_QUAL_SERVICE_PROFILE) + IPC_STR(IPC_GPRS_IP_CONFIGURATION) + IPC_STR(IPC_GPRS_DEFINE_SEC_PDP_CONTEXT) + IPC_STR(IPC_GPRS_TFT) + IPC_STR(IPC_GPRS_HSDPA_STATUS) + IPC_STR(IPC_GPRS_CURRENT_SESSION_DATA_COUNT) + IPC_STR(IPC_GPRS_DATA_DORMANT) + IPC_STR(IPC_GPRS_DUN_PIN_CTRL) + IPC_STR(IPC_GPRS_CALL_STATUS) + IPC_STR(IPC_SAT_PROFILE_DOWNLOAD) + IPC_STR(IPC_SAT_ENVELOPE_CMD) + IPC_STR(IPC_SAT_PROACTIVE_CMD) + IPC_STR(IPC_SAT_TERMINATE_USAT_SESSION) + IPC_STR(IPC_SAT_EVENT_DOWNLOAD) + IPC_STR(IPC_SAT_PROVIDE_LOCAL_INFO) + IPC_STR(IPC_SAT_POLLING) + IPC_STR(IPC_SAT_REFRESH) + IPC_STR(IPC_SAT_SETUP_EVENT_LIST) + IPC_STR(IPC_SAT_CALL_CONTROL_RESULT) + IPC_STR(IPC_SAT_IMAGE_CLUT) + IPC_STR(IPC_SAT_CALL_PROCESSING) + IPC_STR(IPC_IMEI_START) + IPC_STR(IPC_IMEI_CHECK_DEVICE_INFO) + IPC_STR(IPC_GEN_PHONE_RES) + default: + return "IPC_UNKNOWN"; + } +} + @@ -1,70 +0,0 @@ -/** - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -#include <stdio.h> -#include <radio.h> -#include "radio_internal.h" - -void ipc_misc_me_version(int request_id) -{ - ipc_send_get(IPC_MISC_ME_VERSION, request_id); -} - -void ipc_misc_me_imsi(int request_id) -{ - ipc_send_get(IPC_MISC_ME_IMSI, request_id); -} - -/** - * Requests the device's IMEI/IMEISV - */ -void ipc_misc_me_sn(int request_id) -{ - ipc_send_get(IPC_MISC_ME_SN, request_id); -} - -void ipc_rx_misc_me_sn(struct ipc_request_info *info, char *data, int len) -{ - unsigned char *imei_len = (unsigned char*)data; - char *imei = (data+1); - - printf("IMEISV (%u): %s\n", *imei_len, imei); - - info->data = imei; - info->length = *imei_len; - ipc_rx_callback(info); -} - -void ipc_rx_misc_time_info(struct ipc_request_info *info, char *data, int len) -{ - if(len != sizeof(struct ipc_misc_time_info)) { - printf("Invalid NITZ message length\n"); - return; - } - - struct ipc_misc_time_info *nitz = (struct ipc_misc_time_info*)data; - printf("%s: %02u-%02u-%04u %02u:%02u:%02u %02u\n", - __FUNCTION__, nitz->day, nitz->mon, (2000 + nitz->year), - nitz->hour, nitz->min, nitz->sec, nitz->tz); - - info->data = nitz; - info->length = sizeof(*nitz); - ipc_rx_callback(info); -} @@ -1,83 +0,0 @@ -/** - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -#include <radio.h> -#include "radio_internal.h" - -/** - * Requests the current PLMN - */ -void ipc_net_current_plmn(int request_id) -{ - ipc_send_get(IPC_NET_CURRENT_PLMN, request_id); -} - -void ipc_rx_net_current_plmn(struct ipc_request_info *info, char *data, int len) -{ - struct ipc_net_current_plmn *plmndata = (struct ipc_net_current_plmn*)data; - - info->data = plmndata; - info->length = sizeof(*plmndata); - ipc_rx_callback(info); -} - -void ipc_net_plmn_list(int request_id) -{ - ipc_send_get(IPC_NET_PLMN_LIST, request_id); -} - -void ipc_rx_net_plmn_list(struct ipc_request_info *info, char *data, int len) -{ - unsigned char num_entries = *((unsigned char*)data); - - struct ipc_net_plmn_entries entries; - entries.num = num_entries; - entries.data = (struct ipc_net_plmn_entry*)(data+1); - - info->data = &entries; - info->length = sizeof(entries); - ipc_rx_callback(info); -} - -void ipc_rx_net_regist(struct ipc_request_info *info, const char *data, int len) -{ - struct ipc_net_regist *netinfo = (struct ipc_net_regist*)data; - - info->data = netinfo; - info->length = sizeof(*netinfo); - ipc_rx_callback(info); -} - -void ipc_net_identity(int request_id) -{ - ipc_send_get(IPC_NET_IDENTITY, request_id); -} - -void ipc_net_regist(int request_id, unsigned char type) -{ - unsigned char data[] = { 0xff, 0x00 }; - if(type == 0) { - ipc_send_get(IPC_NET_REGIST, request_id); - } else { - data[1] = type; - ipc_send(IPC_NET_REGIST, IPC_TYPE_GET, data, sizeof(data), request_id); - } -} - diff --git a/radio.c b/radio.c deleted file mode 100644 index 35faf86..0000000 --- a/radio.c +++ /dev/null @@ -1,345 +0,0 @@ -/** - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <termios.h> -#include <unistd.h> -#include <fcntl.h> -#include <pthread.h> -#include <sys/select.h> -#include <radio.h> - -#include "radio_internal.h" -#include "hexdump.h" - -static int fd = 0; -static struct ipc_info *ipc = NULL; - -void ipc_rx_callback(struct ipc_request_info *info) -{ - ipc->on_receive(info); -} - -void ipc_register(struct ipc_info *ipc_data) -{ - ipc = ipc_data; -} - -void ipc_open() -{ - fd = open(ipc->tty, O_RDWR | O_NDELAY); - - if(fd < 0) { - printf("Failed to open dpram tty\n"); - } - - struct termios termios; - - tcgetattr(fd, &termios); - cfmakeraw(&termios); - tcsetattr(fd, TCSANOW, &termios); -} - -void ipc_close() -{ - if(fd) { - close(fd); - } -} - -void ipc_power_on() -{ - ioctl(fd, IOCTL_PHONE_ON); -} - -void ipc_power_off() -{ - ioctl(fd, IOCTL_PHONE_OFF); -} - -const char *ipc_type(struct ipc_hdr *frame) { - switch(frame->type) { - case IPC_TYPE_INDI: - return "INDI"; - case IPC_TYPE_RESP: - return "RESP"; - case IPC_TYPE_NOTI: - return "NOTI"; - default: - return "UNKNOWN"; - } -} - -const char *ipc_str(struct ipc_hdr *frame) { - switch(FRAME_ID(frame)) { - FRAME_STR(IPC_PWR_PHONE_PWR_UP) - FRAME_STR(IPC_PWR_PHONE_PWR_OFF) - FRAME_STR(IPC_PWR_PHONE_RESET) - FRAME_STR(IPC_PWR_BATT_STATUS) - FRAME_STR(IPC_PWR_BATT_TYPE) - FRAME_STR(IPC_PWR_BATT_COMP) - FRAME_STR(IPC_PWR_PHONE_ONLINE) - FRAME_STR(IPC_CALL_OUTGOING) - FRAME_STR(IPC_CALL_INCOMING) - FRAME_STR(IPC_CALL_RELEASE) - FRAME_STR(IPC_CALL_ANSWER) - FRAME_STR(IPC_CALL_STATUS) - FRAME_STR(IPC_CALL_LIST) - FRAME_STR(IPC_CALL_BURST_DTMF) - FRAME_STR(IPC_CALL_CONT_DTMF) - FRAME_STR(IPC_CALL_WAITING) - FRAME_STR(IPC_CALL_LINE_ID) - FRAME_STR(IPC_SMS_SEND_MSG) - FRAME_STR(IPC_SMS_INCOMING_MSG) - FRAME_STR(IPC_SMS_READ_MSG) - FRAME_STR(IPC_SMS_SAVE_MSG) - FRAME_STR(IPC_SMS_DEL_MSG) - FRAME_STR(IPC_SMS_DELIVER_REPORT) - FRAME_STR(IPC_SMS_DEVICE_READY) - FRAME_STR(IPC_SMS_SEL_MEM) - FRAME_STR(IPC_SMS_STORED_MSG_COUNT) - FRAME_STR(IPC_SMS_SVC_CENTER_ADDR) - FRAME_STR(IPC_SMS_SVC_OPTION) - FRAME_STR(IPC_SMS_MEM_STATUS) - FRAME_STR(IPC_SMS_CBS_MSG) - FRAME_STR(IPC_SMS_CBS_CONFIG) - FRAME_STR(IPC_SMS_STORED_MSG_STATUS) - FRAME_STR(IPC_SMS_PARAM_COUNT) - FRAME_STR(IPC_SMS_PARAM) - FRAME_STR(IPC_SEC_PIN_STATUS) - FRAME_STR(IPC_SEC_PHONE_LOCK) - FRAME_STR(IPC_SEC_CHANGE_LOCKING_PW) - FRAME_STR(IPC_SEC_SIM_LANG) - FRAME_STR(IPC_SEC_RSIM_ACCESS) - FRAME_STR(IPC_SEC_GSIM_ACCESS) - FRAME_STR(IPC_SEC_SIM_ICC_TYPE) - FRAME_STR(IPC_SEC_LOCK_INFO) - FRAME_STR(IPC_SEC_ISIM_AUTH) - FRAME_STR(IPC_PB_ACCESS) - FRAME_STR(IPC_PB_STORAGE) - FRAME_STR(IPC_PB_STORAGE_LIST) - FRAME_STR(IPC_PB_ENTRY_INFO) - FRAME_STR(IPC_PB_CAPABILITY_INFO) - FRAME_STR(IPC_DISP_ICON_INFO) - FRAME_STR(IPC_DISP_HOMEZONE_INFO) - FRAME_STR(IPC_NET_PREF_PLMN) - FRAME_STR(IPC_NET_PLMN_SEL) - FRAME_STR(IPC_NET_CURRENT_PLMN) - FRAME_STR(IPC_NET_PLMN_LIST) - FRAME_STR(IPC_NET_REGIST) - FRAME_STR(IPC_NET_SUBSCRIBER_NUM) - FRAME_STR(IPC_NET_BAND_SEL) - FRAME_STR(IPC_NET_SERVICE_DOMAIN_CONFIG) - FRAME_STR(IPC_NET_POWERON_ATTACH) - FRAME_STR(IPC_NET_MODE_SEL) - FRAME_STR(IPC_NET_ACQ_ORDER) - FRAME_STR(IPC_NET_IDENTITY) - FRAME_STR(IPC_NET_CURRENT_RRC_STATUS) - FRAME_STR(IPC_MISC_ME_VERSION) - FRAME_STR(IPC_MISC_ME_IMSI) - FRAME_STR(IPC_MISC_ME_SN) - FRAME_STR(IPC_MISC_TIME_INFO) - FRAME_STR(IPC_SS_WAITING) - FRAME_STR(IPC_SS_CLI) - FRAME_STR(IPC_SS_BARRING) - FRAME_STR(IPC_SS_BARRING_PW) - FRAME_STR(IPC_SS_FORWARDING) - FRAME_STR(IPC_SS_INFO) - FRAME_STR(IPC_SS_MANAGE_CALL) - FRAME_STR(IPC_SS_USSD) - FRAME_STR(IPC_SS_AOC) - FRAME_STR(IPC_SS_RELEASE_COMPLETE) - FRAME_STR(IPC_GPRS_DEFINE_PDP_CONTEXT) - FRAME_STR(IPC_GPRS_QOS) - FRAME_STR(IPC_GPRS_PS) - FRAME_STR(IPC_GPRS_PDP_CONTEXT) - FRAME_STR(IPC_GPRS_SHOW_PDP_ADDR) - FRAME_STR(IPC_GPRS_MS_CLASS) - FRAME_STR(IPC_GPRS_3G_QUAL_SERVICE_PROFILE) - FRAME_STR(IPC_GPRS_IP_CONFIGURATION) - FRAME_STR(IPC_GPRS_DEFINE_SEC_PDP_CONTEXT) - FRAME_STR(IPC_GPRS_TFT) - FRAME_STR(IPC_GPRS_HSDPA_STATUS) - FRAME_STR(IPC_GPRS_CURRENT_SESSION_DATA_COUNT) - FRAME_STR(IPC_GPRS_DATA_DORMANT) - FRAME_STR(IPC_GPRS_DUN_PIN_CTRL) - FRAME_STR(IPC_GPRS_CALL_STATUS) - FRAME_STR(IPC_SAT_PROFILE_DOWNLOAD) - FRAME_STR(IPC_SAT_ENVELOPE_CMD) - FRAME_STR(IPC_SAT_PROACTIVE_CMD) - FRAME_STR(IPC_SAT_TERMINATE_USAT_SESSION) - FRAME_STR(IPC_SAT_EVENT_DOWNLOAD) - FRAME_STR(IPC_SAT_PROVIDE_LOCAL_INFO) - FRAME_STR(IPC_SAT_POLLING) - FRAME_STR(IPC_SAT_REFRESH) - FRAME_STR(IPC_SAT_SETUP_EVENT_LIST) - FRAME_STR(IPC_SAT_CALL_CONTROL_RESULT) - FRAME_STR(IPC_SAT_IMAGE_CLUT) - FRAME_STR(IPC_SAT_CALL_PROCESSING) - FRAME_STR(IPC_IMEI_START) - FRAME_STR(IPC_IMEI_CHECK_DEVICE_INFO) - FRAME_STR(IPC_GEN_PHONE_RES) - default: - return "UNKNOWN_FRAME"; - } -} - -void ipc_tx(const char *data, const int length) -{ - unsigned int frame_len = (length+2); - - char *hdlc = malloc(frame_len); - hdlc[0] = FRAME_START; - hdlc[length+1] = FRAME_END; - - memcpy(hdlc+1, data, length); - - hex_dump(hdlc, frame_len); - printf("\n"); - - write(fd, hdlc, frame_len); - free(hdlc); -} - -void ipc_send(const int type, const int method, const unsigned char *data, const int data_length, int request_id) -{ - struct ipc_hdr header; - unsigned int len = sizeof(header); - unsigned int frame_length = (len + data_length); - char *frame = malloc(frame_length); - - memset(&header, 0x00, len); - header.frame_len = frame_length; - header.seqnum = request_id; //fixme - header.reqid = 0xff; //fixme - header.len = (frame_length - 3); - header.group = FRAME_GRP(type); - header.index = FRAME_IDX(type); - header.type = method; - - memcpy(frame, &header, sizeof(header)); - memcpy(frame+len, data, data_length); - - printf("\n%s: %s\n", __FUNCTION__, ipc_str(&header)); - ipc_tx(frame, frame_length); - free(frame); -} - -void ipc_send_get(const int type, int request_id) -{ - ipc_send(type, IPC_TYPE_GET, NULL, 0, request_id); -} - -void ipc_send_exec(const int type, int request_id) -{ - ipc_send(type, IPC_TYPE_EXEC, NULL, 0, request_id); -} - -void ipc_pwr_phone_pwr_up(struct ipc_request_info *info, const char *data, const int len) -{ - /* Modem reports bogus IMEI if queried right after powerup */ - usleep(25000); - ipc_rx_callback(info); -} - -void ipc_decode_frame(char *frame, int length) { - struct ipc_hdr *header = (struct ipc_hdr*)frame; - char *data = frame + sizeof(*header); - - unsigned short data_len = (header->frame_len - sizeof(*header)); - unsigned char request_id = header->reqid; - - struct ipc_request_info request_info; - request_info.type = FRAME_ID(header); - request_info.id = request_id; - request_info.method = header->type; - - /* FIXME: These args are also passed to each handler below? */ - request_info.data = data; - request_info.length = data_len; - - printf("%s %s (%u/%u) seq=%d req=%d\n", ipc_str(header), ipc_type(header), header->frame_len, data_len, header->seqnum, header->reqid); - hex_dump(frame, length); - - switch(request_info.type) { - /* Power */ - case IPC_PWR_PHONE_PWR_UP: - ipc_pwr_phone_pwr_up(&request_info, data, data_len); - break; - /* Misc */ - case IPC_MISC_ME_SN: - ipc_rx_misc_me_sn(&request_info, data, data_len); - break; - case IPC_MISC_TIME_INFO: - ipc_rx_misc_time_info(&request_info, data, data_len); - break; - /* Net */ - case IPC_NET_CURRENT_PLMN: - ipc_rx_net_current_plmn(&request_info, data, data_len); - break; - case IPC_NET_PLMN_LIST: - ipc_rx_net_plmn_list(&request_info, data, data_len); - break; - case IPC_NET_REGIST: - ipc_rx_net_regist(&request_info, data, data_len); - break; - default: - ipc_rx_callback(&request_info); - break; - } - - printf("\n"); -} - -void ipc_loop() -{ - unsigned char frame_len; - char *buf = malloc(1024); - if(!buf) { - printf("Failed to alloc receive buf\n"); - return; - } - - fd_set fds; - - FD_ZERO(&fds); - FD_SET(fd, &fds); - - while(1) { - select(fd+1, &fds, NULL, NULL, NULL); - int num_read = read(fd, buf, 1024); - - char *p = buf; - char *frame = NULL; - - while(p < (buf+num_read)) { - if(*p == FRAME_START) { - frame = (p+1); - frame_len = *frame; - } else if(*p == FRAME_END && p == (frame+frame_len)) { - ipc_decode_frame(frame, (p - frame)); - } - - p++; - } - } -} diff --git a/radio_internal.h b/radio_internal.h deleted file mode 100644 index 41ca2f2..0000000 --- a/radio_internal.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -#include <radio.h> - -#define IOCTL_PHONE_ON 0x68d0 -#define IOCTL_PHONE_OFF 0x68d1 -#define IOCTL_PHONE_GETSTATUS 0x68d2 -#define IOCTL_PHONE_RESET 0x68d3 -#define IOCTL_PHONE_RAMDUMP 0x68d4 -#define IOCTL_PHONE_BOOTTYPE 0x68d5 -#define IOCTL_MEM_RW 0x68d6 -#define IOCTL_WAKEUP 0x68d7 -#define IOCTL_SILENT_RESET 0x68d8 - -#ifdef ANDROID - -#define LOG_TAG "RIL" -#include <utils/Log.h> -#define printf LOGI - -#endif - -/* Receive callback */ -void ipc_rx_callback(struct ipc_request_info *info); - -void ipc_send_get(const int type, int request_id); -void ipc_send_exec(const int type, int request_id); - -/* Misc */ -void ipc_rx_misc_me_sn(struct ipc_request_info *info, char *data, int len); -void ipc_rx_misc_time_info(struct ipc_request_info *info, char *data, int len); - -/* Net */ -void ipc_rx_net_current_plmn(struct ipc_request_info *info, char *data, int len); -void ipc_rx_net_plmn_list(struct ipc_request_info *info, char *data, int len); -void ipc_rx_net_regist(struct ipc_request_info *info, const char *data, int len); - - -struct ipc_hdr { - unsigned short frame_len; - unsigned char unk; - unsigned short len; - unsigned char seqnum, reqid, group, index, type; -} __attribute__((__packed__)); @@ -1,47 +0,0 @@ -/** - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - * - */ - -#include "radio_internal.h" - -void ipc_sec_rsim_access(unsigned char command, unsigned short file_id, - unsigned char p1, unsigned char p2, unsigned char p3, - unsigned char *rdata, unsigned int length, int request_id) -{ - unsigned char msg[262]; - struct ipc_sec_rsim_access_request *rsim_req = (struct ipc_sec_rsim_access_request*)&msg[0]; - unsigned char *data = (msg + sizeof(*rsim_req)); - - memset(msg, 0, sizeof(msg)); - - rsim_req->command = command; - rsim_req->fileid = file_id; - rsim_req->p1 = p1; - rsim_req->p2 = p2; - rsim_req->p3 = p3; - - if(length > 256) { - length = 256; - } - - memcpy(data, rdata, length); - - ipc_send(IPC_SEC_RSIM_ACCESS, IPC_TYPE_GET, msg, sizeof(msg), request_id); -} - @@ -17,27 +17,69 @@ * along with libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>. * */ +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> #include <radio.h> -static void on_receive(struct ipc_request_info *info) +void handle_msg(struct ipc_response *response) { -} + if(response->command == IPC_PWR_PHONE_PWR_UP && + response->type == IPC_TYPE_NOTI) { + printf(">> received PWR_PHONE_ONLINE, requesting IMEI\n"); -static struct ipc_info ipc = { - .tty = "/dev/dpram0", - .on_receive = on_receive, -}; + /* h1 requires a short delay for nvram to be available */ + usleep(25000); + ipc_msg_send(IPC_MISC_ME_SN, IPC_TYPE_GET, NULL, 0, 0x42); + } +} int main(int argc, char *argv[]) { - ipc_register(&ipc); - ipc_open(); + struct ipc_response response; + int error; + + printf("ipc_open\n"); + error = ipc_open(); + + if(error) { + fprintf(stderr, "ipc_open failed!\n"); + return 1; + } + + printf("ipc_power_on\n"); ipc_power_on(); - ipc_loop(); + printf("entering recv loop...\n"); + + while(1) { + error = ipc_recv(&response); + + if(!error) { + printf("%s %s (%u/%u) type=%04x mseq=%02x aseq=%02x\n", + ipc_str(&response), ipc_response_type(&response), + (response.data_length + 7), response.data_length, + response.type, response.mseq, response.aseq); + + hex_dump(response.data, response.data_length); + printf("\n"); + + handle_msg(&response); + + free(response.data); + } else { + fprintf(stderr, "ipc_recv failed!\n"); + return 1; + } + } + + error = ipc_close(); - ipc_close(); + if(error) { + fprintf(stderr, "ipc_close failed!\n"); + return 1; + } return 0; } @@ -21,9 +21,8 @@ #include <stdio.h> #include <string.h> #include <ctype.h> -#include "hexdump.h" -#ifdef ANDROID +#if defined(ANDROID) && !defined(LOG_STDOUT) #define LOG_TAG "RIL" #include <utils/Log.h> |