aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2014-02-09 13:51:38 +0100
committerPaul Kocialkowski <contact@paulk.fr>2014-02-09 13:51:38 +0100
commit828f125ee5957ee3f64d45329f5ac261a2a3c1a7 (patch)
tree7cb2c2433a4fae20f660dd60819350034ea1ebeb
parent6cb0b59e3f0a7b8f2c9690b7e8d171d88d000270 (diff)
downloadhardware_replicant_libsamsung-ipc-828f125ee5957ee3f64d45329f5ac261a2a3c1a7.tar.gz
hardware_replicant_libsamsung-ipc-828f125ee5957ee3f64d45329f5ac261a2a3c1a7.tar.bz2
hardware_replicant_libsamsung-ipc-828f125ee5957ee3f64d45329f5ac261a2a3c1a7.zip
Consistent coding style in helpers
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--include/call.h32
-rw-r--r--include/gen.h10
-rw-r--r--include/gprs.h15
-rw-r--r--include/misc.h6
-rw-r--r--include/net.h6
-rw-r--r--include/sec.h21
-rw-r--r--include/sms.h6
-rw-r--r--samsung-ipc/call.c127
-rw-r--r--samsung-ipc/gen.c19
-rw-r--r--samsung-ipc/gprs.c67
-rw-r--r--samsung-ipc/misc.c24
-rw-r--r--samsung-ipc/net.c65
-rw-r--r--samsung-ipc/sec.c160
-rw-r--r--samsung-ipc/sms.c40
14 files changed, 339 insertions, 259 deletions
diff --git a/include/call.h b/include/call.h
index a98f847..92cb563 100644
--- a/include/call.h
+++ b/include/call.h
@@ -104,6 +104,10 @@ struct ipc_call_status_data {
unsigned char end_cause; // IPC_CALL_END_CAUSE
} __attribute__((__packed__));
+struct ipc_call_list_header {
+ unsigned char count;
+} __attribute__((__packed__));
+
struct ipc_call_list_entry {
unsigned char unknown1;
unsigned char type; // IPC_CALL_TYPE
@@ -115,6 +119,15 @@ struct ipc_call_list_entry {
unsigned char unknown3;
} __attribute__((__packed__));
+struct ipc_call_burst_dtmf_header {
+ unsigned char count;
+} __attribute__((__packed__));
+
+struct ipc_call_burst_dtmf_entry {
+ unsigned char state;
+ unsigned char tone;
+} __attribute__((__packed__));
+
struct ipc_call_cont_dtmf_data {
unsigned char state;
unsigned char tone;
@@ -124,15 +137,16 @@ struct ipc_call_cont_dtmf_data {
* Helpers
*/
-void ipc_call_outgoing_setup(struct ipc_call_outgoing_data *message, unsigned char type,
- unsigned char identity, unsigned char prefix, char *number);
-unsigned int ipc_call_list_response_get_num_entries(struct ipc_message_info *response);
-struct ipc_call_list_entry* ipc_call_list_response_get_entry(struct ipc_message_info *response,
- unsigned int num);
-char *ipc_call_list_response_get_entry_number(struct ipc_message_info *response,
- unsigned int num);
-unsigned char *ipc_call_cont_dtmf_burst_pack(struct ipc_call_cont_dtmf_data *message,
- unsigned char *burst, int burst_len);
+int ipc_call_outgoing_setup(struct ipc_call_outgoing_data *data,
+ unsigned char type, unsigned char identity, unsigned char prefix,
+ const char *number);
+unsigned char ipc_call_list_get_count(const void *data, size_t size);
+struct ipc_call_list_entry *ipc_call_list_get_entry(const void *data,
+ size_t size, unsigned int index);
+char *ipc_call_list_get_entry_number(const void *data,
+ size_t size, unsigned int index);
+void *ipc_call_burst_dtmf_setup(const struct ipc_call_burst_dtmf_entry *entries,
+ unsigned char count);
#endif
diff --git a/include/gen.h b/include/gen.h
index 49e6f4a..8013df6 100644
--- a/include/gen.h
+++ b/include/gen.h
@@ -2,7 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
- * Copyright (C) 2011-2013 Paul Kocialkowski <contact@paulk.fr>
+ * Copyright (C) 2011-2014 Paul Kocialkowski <contact@paulk.fr>
*
* 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
@@ -30,6 +30,12 @@
#define IPC_GEN_PHONE_RES 0x8001
/*
+ * Values
+ */
+
+#define IPC_GEN_PHONE_RES_CODE_SUCCESS 0x8000
+
+/*
* Structures
*/
@@ -44,7 +50,7 @@ struct ipc_gen_phone_res_data {
* Helpers
*/
-int ipc_gen_phone_res_check(struct ipc_gen_phone_res_data *res);
+int ipc_gen_phone_res_check(const struct ipc_gen_phone_res_data *data);
#endif
diff --git a/include/gprs.h b/include/gprs.h
index 0b5dcc9..568892d 100644
--- a/include/gprs.h
+++ b/include/gprs.h
@@ -78,11 +78,11 @@ struct ipc_gprs_define_pdp_context_data {
struct ipc_gprs_pdp_context_request_set_data {
unsigned char enable;
unsigned char cid;
- unsigned char magic[4];
+ unsigned char magic1[4];
unsigned char username[32];
unsigned char password[32];
unsigned char unknown1[32];
- unsigned char unknown2;
+ unsigned char magic2;
} __attribute__((__packed__));
struct ipc_gprs_pdp_context_request_get_entry {
@@ -131,11 +131,12 @@ struct ipc_gprs_port_list_data {
* Helpers
*/
-void ipc_gprs_port_list_setup(struct ipc_gprs_port_list_data *message);
-void ipc_gprs_pdp_context_request_set_setup(struct ipc_gprs_pdp_context_request_set_data *message,
- unsigned char cid, int enable, char *username, char *password);
-void ipc_gprs_define_pdp_context_setup(struct ipc_gprs_define_pdp_context_data *message,
- unsigned char cid, int enable, char *apn);
+int ipc_gprs_define_pdp_context_setup(struct ipc_gprs_define_pdp_context_data *data,
+ unsigned char enable, unsigned char cid, const char *apn);
+int ipc_gprs_pdp_context_request_set_setup(struct ipc_gprs_pdp_context_request_set_data *data,
+ unsigned char enable, unsigned char cid, const char *username,
+ const char *password);
+int ipc_gprs_port_list_setup(struct ipc_gprs_port_list_data *data);
#endif
diff --git a/include/misc.h b/include/misc.h
index 78e993b..f40b1f0 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -55,6 +55,10 @@ struct ipc_misc_me_version_data {
char misc[32];
} __attribute__((__packed__));
+struct ipc_misc_me_imsi_header {
+ unsigned char length;
+} __attribute__((__packed__));
+
struct ipc_misc_me_sn_data {
unsigned char type; // IPC_MISC_ME_SN_SERIAL_NUM
unsigned char length;
@@ -73,7 +77,7 @@ struct ipc_misc_time_info_data {
* Helpers
*/
-char *ipc_misc_me_imsi_response_get_imsi(struct ipc_message_info *response);
+char *ipc_misc_me_imsi_get_imsi(const void *data, size_t size);
#endif
diff --git a/include/net.h b/include/net.h
index 310a12d..7e7809e 100644
--- a/include/net.h
+++ b/include/net.h
@@ -129,10 +129,10 @@ struct ipc_net_mode_sel_data {
* Helpers
*/
-void ipc_net_regist_setup(struct ipc_net_regist_request_data *message,
+int ipc_net_plmn_sel_setup(struct ipc_net_plmn_sel_request_data *data,
+ unsigned char mode_sel, const char *plmn, unsigned char act);
+int ipc_net_regist_setup(struct ipc_net_regist_request_data *data,
unsigned char domain);
-void ipc_net_plmn_sel_set_setup(struct ipc_net_plmn_sel_request_data *message,
- unsigned char mode, char *plmn, unsigned char act);
#endif
diff --git a/include/sec.h b/include/sec.h
index 052737a..48968e9 100644
--- a/include/sec.h
+++ b/include/sec.h
@@ -2,7 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
- * Copyright (C) 2011-2013 Paul Kocialkowski <contact@paulk.fr>
+ * Copyright (C) 2011-2014 Paul Kocialkowski <contact@paulk.fr>
*
* 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
@@ -166,15 +166,16 @@ struct ipc_sec_lock_infomation_response_data {
* Helpers
*/
-void ipc_sec_pin_status_setup(struct ipc_sec_pin_status_request_data *message,
- unsigned char pin_type, char *pin1, char *pin2);
-void ipc_sec_lock_infomation_setup(struct ipc_sec_lock_infomation_request_data *message,
- unsigned char pin_type);
-void ipc_sec_phone_lock_request_set_setup(struct ipc_sec_phone_lock_request_set_data *message,
- int pin_type, int enable, char *passwd);
-char *ipc_sec_rsim_access_response_get_file_data(struct ipc_message_info *response);
-void ipc_sec_change_locking_pw_setup(struct ipc_sec_change_locking_pw_data *message,
- int type, char *passwd_old, char *passwd_new);
+int ipc_sec_pin_status_setup(struct ipc_sec_pin_status_request_data *data,
+ unsigned char type, const char *pin1, const char *pin2);
+int ipc_sec_phone_lock_request_set_setup(struct ipc_sec_phone_lock_request_set_data *data,
+ unsigned char facility_type, unsigned char active, const char *password);
+int ipc_sec_change_locking_pw_setup(struct ipc_sec_change_locking_pw_data *data,
+ unsigned char facility_type, const char *password_old,
+ const char *password_new);
+void *ipc_sec_rsim_access_get_file_data(const void *data, size_t size);
+int ipc_sec_lock_infomation_setup(struct ipc_sec_lock_infomation_request_data *data,
+ unsigned char type);
#endif
diff --git a/include/sms.h b/include/sms.h
index cb49df2..2d05571 100644
--- a/include/sms.h
+++ b/include/sms.h
@@ -2,7 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
- * Copyright (C) 2011 Paul Kocialkowski <contact@paulk.fr>
+ * Copyright (C) 2011-2014 Paul Kocialkowski <contact@paulk.fr>
*
* 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
@@ -131,8 +131,8 @@ struct ipc_sms_save_msg_response_data {
* Helpers
*/
-unsigned char *ipc_sms_send_msg_pack(struct ipc_sms_send_msg_request_header *msg, char *smsc,
- unsigned char *pdu, int pdu_length);
+void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header,
+ const char *smsc, const char *pdu);
#endif
diff --git a/samsung-ipc/call.c b/samsung-ipc/call.c
index c5c0c21..ba7097e 100644
--- a/samsung-ipc/call.c
+++ b/samsung-ipc/call.c
@@ -2,7 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
- * Copyright (C) 2013 Paul Kocialkowsk <contact@paulk.fr>
+ * Copyright (C) 2013-2014 Paul Kocialkowsk <contact@paulk.fr>
*
* 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
@@ -23,105 +23,110 @@
#include <samsung-ipc.h>
-#define OUTGOING_NUMBER_MAX_LENGTH 86
-
-void ipc_call_outgoing_setup(struct ipc_call_outgoing_data *message, unsigned char type,
- unsigned char identity, unsigned char prefix, char *number)
+int ipc_call_outgoing_setup(struct ipc_call_outgoing_data *data,
+ unsigned char type, unsigned char identity, unsigned char prefix,
+ const char *number)
{
- int length;
+ size_t number_length;
- if (message == NULL || number == NULL)
- return;
+ if (data == NULL || number == NULL)
+ return -1;
- length = strlen(number);
- if (length > OUTGOING_NUMBER_MAX_LENGTH)
- length = OUTGOING_NUMBER_MAX_LENGTH;
+ number_length = strlen(number);
+ if (number_length > sizeof(data->number))
+ number_length = sizeof(data->number);
- memset(message, 0, sizeof(struct ipc_call_outgoing_data));
+ memset(data, 0, sizeof(struct ipc_call_outgoing_data));
+ data->type = type;
+ data->identity = identity;
+ data->prefix = prefix;
+ data->number_length = (unsigned char) number_length;
- message->type = type;
- message->identity = identity;
- message->prefix = prefix;
- message->number_length = length;
+ strncpy((char *) data->number, number, number_length);
- strncpy((char *) message->number, number, length);
+ return 0;
}
-/* Retrieve number of calls in list of calls */
-unsigned int ipc_call_list_response_get_num_entries(struct ipc_message_info *response)
+unsigned char ipc_call_list_get_count(const void *data, size_t size)
{
- if (response == NULL || response->data == NULL || response->length < sizeof(unsigned int))
+ struct ipc_call_list_header *header;
+
+ if (data == NULL || size < sizeof(struct ipc_call_list_header))
return 0;
- return *((unsigned int *) response->data);
+ header = (struct ipc_call_list_header *) data;
+
+ return header->count;
}
-/* Retrieve one specific entry from a list of calls */
-struct ipc_call_list_entry* ipc_call_list_response_get_entry(struct ipc_message_info *response,
- unsigned int num)
+struct ipc_call_list_entry *ipc_call_list_get_entry(const void *data,
+ size_t size, unsigned int index)
{
- unsigned int count, pos, n;
struct ipc_call_list_entry *entry = NULL;
+ unsigned char count;
+ unsigned char i;
+ size_t offset;
- count = ipc_call_list_response_get_num_entries(response);
- if (num > count || count == 0)
+ if (data == NULL)
return NULL;
- pos = 1;
- for (n = 0; n < num + 1; n++)
- {
- entry = (struct ipc_call_list_entry *) (response->data + pos);
- pos += (unsigned int) (sizeof(struct ipc_call_list_entry) + entry->number_length);
+ count = ipc_call_list_get_count(data, size);
+ if (count == 0)
+ return NULL;
+
+ offset = sizeof(struct ipc_call_list_header);
+
+ for (i = 0; i < (index + 1); i++) {
+ entry = (struct ipc_call_list_entry *) ((unsigned char *) data + offset);
+ offset += sizeof(struct ipc_call_list_entry) + entry->number_length;
}
+ if (offset > size)
+ return NULL;
+
return entry;
}
-/* Retrieve the number of a call entry in the list of calls */
-char *ipc_call_list_response_get_entry_number(struct ipc_message_info *response,
- unsigned int num)
+char *ipc_call_list_get_entry_number(const void *data,
+ size_t size, unsigned int index)
{
- unsigned int count, pos, n;
- struct ipc_call_list_entry *entry = NULL;
+ struct ipc_call_list_entry *entry;
char *number;
+ size_t number_length;
- count = ipc_call_list_response_get_num_entries(response);
- if (num > count || count == 0)
+ entry = ipc_call_list_get_entry(data, size, index);
+ if (entry == NULL)
return NULL;
- pos = 1;
- for (n = 0; n < num + 1; n++)
- {
- if (entry != NULL)
- pos += entry->number_length;
+ // entry->number_length doesn't count the final null character
+ number_length = entry->number_length + sizeof(char);
- entry = (struct ipc_call_list_entry *) (response->data + pos);
- pos += (unsigned int) sizeof(struct ipc_call_list_entry);
- }
+ number = (char *) calloc(1, number_length);
- if (entry == NULL || (unsigned char *) (response->data + pos) == NULL)
- return NULL;
-
- number = (char *) malloc(sizeof(char) * entry->number_length);
- strncpy(number, (char *) (response->data + pos), entry->number_length);
+ strncpy(number, (char *) entry + sizeof(struct ipc_call_list_entry), entry->number_length);
+ number[entry->number_length] = '\0';
return number;
}
-unsigned char *ipc_call_cont_dtmf_burst_pack(struct ipc_call_cont_dtmf_data *message,
- unsigned char *burst, int burst_len)
+void *ipc_call_burst_dtmf_setup(const struct ipc_call_burst_dtmf_entry *entries,
+ unsigned char count)
{
- unsigned char *data = NULL;
- int data_len = sizeof(struct ipc_call_cont_dtmf_data) + burst_len;
+ struct ipc_call_burst_dtmf_header *header;
+ void *data;
+ size_t size;
- if (message == NULL || burst == NULL || burst_len <= 0)
+ if (entries == NULL)
return NULL;
- data = (unsigned char *) malloc(sizeof(unsigned char) * data_len);
- memset(data, 0, data_len);
+ size = sizeof(struct ipc_call_burst_dtmf_header) + count * sizeof(struct ipc_call_burst_dtmf_entry);
+
+ data = calloc(1, size);
+
+ header = (struct ipc_call_burst_dtmf_header *) data;
+ header->count = count;
- memcpy(data, message, sizeof(struct ipc_call_cont_dtmf_data));
- memcpy(data + sizeof(struct ipc_call_cont_dtmf_data), burst, burst_len);
+ memcpy((void *) ((unsigned char *) data + sizeof(struct ipc_call_burst_dtmf_header)), entries, count * sizeof(struct ipc_call_burst_dtmf_entry));
return data;
}
diff --git a/samsung-ipc/gen.c b/samsung-ipc/gen.c
index 6db041b..93eaeaa 100644
--- a/samsung-ipc/gen.c
+++ b/samsung-ipc/gen.c
@@ -1,7 +1,7 @@
/*
* This file is part of libsamsung-ipc.
*
- * Copyright (C) 2011 Paul Kocialkowsk <contact@paulk.fr>
+ * Copyright (C) 2011-2014 Paul Kocialkowsk <contact@paulk.fr>
*
* 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
@@ -21,20 +21,15 @@
#include <samsung-ipc.h>
-int ipc_gen_phone_res_check(struct ipc_gen_phone_res_data *res)
+int ipc_gen_phone_res_check(const struct ipc_gen_phone_res_data *data)
{
- if (res == NULL)
+ if (data == NULL)
return -1;
- switch(res->code)
- {
- case 0x8000:
- return 0;
- case 0x8001:
- return 0;
- default:
- return -1;
- }
+ if (data->code & IPC_GEN_PHONE_RES_CODE_SUCCESS)
+ return 0;
+
+ return -1;
}
// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/gprs.c b/samsung-ipc/gprs.c
index 7c14df9..a7c0bc1 100644
--- a/samsung-ipc/gprs.c
+++ b/samsung-ipc/gprs.c
@@ -2,6 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
+ * Copyright (C) 2014 Paul Kocialkowski <contact@paulk.fr>
*
* 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
@@ -22,54 +23,56 @@
#include <samsung-ipc.h>
-void ipc_gprs_port_list_setup(struct ipc_gprs_port_list_data *message)
+int ipc_gprs_define_pdp_context_setup(struct ipc_gprs_define_pdp_context_data *data,
+ unsigned char enable, unsigned char cid, const char *apn)
{
- // FIXME: These are only known-to-work values used on most devices
- unsigned char bytes[] = {
- 0x02, 0x04, 0x16, 0x00, 0x17, 0x00, 0x87, 0x00, 0xBD, 0x01
- };
+ if (data == NULL || apn == NULL)
+ return -1;
- if (message == NULL)
- return;
+ memset(data, 0, sizeof(struct ipc_gprs_define_pdp_context_data));
+ data->enable = enable;
+ data->cid = cid;
+ data->magic = 0x02;
- memset(message, 0, sizeof(struct ipc_gprs_port_list_data));
+ strncpy((char *) data->apn, apn, sizeof(data->apn));
- memcpy(message->magic, bytes, sizeof(bytes));
+ return 0;
}
-void ipc_gprs_define_pdp_context_setup(struct ipc_gprs_define_pdp_context_data *message,
- unsigned char cid, int enable, char *apn)
+int ipc_gprs_pdp_context_request_set_setup(struct ipc_gprs_pdp_context_request_set_data *data,
+ unsigned char enable, unsigned char cid, const char *username,
+ const char *password)
{
- if (message == NULL)
- return;
+ if (data == NULL)
+ return -1;
+
+ memset(data, 0, sizeof(struct ipc_gprs_pdp_context_request_set_data));
+ data->enable = enable;
+ data->cid = cid;
- memset(message, 0, sizeof(struct ipc_gprs_define_pdp_context_data));
+ if (enable && username != NULL && password != NULL) {
+ data->magic1[2] = 0x13;
+ data->magic2 = 0x01;
- message->enable = enable ? 1 : 0;
- message->cid = cid;
- message->magic = 0x2;
+ strncpy((char *) data->username, username, sizeof(data->username));
+ strncpy((char *) data->password, password, sizeof(data->password));
+ }
- strncpy((char *) message->apn, apn, 124);
+ return 0;
}
-void ipc_gprs_pdp_context_request_set_setup(struct ipc_gprs_pdp_context_request_set_data *message,
- unsigned char cid, int enable, char *username, char *password)
+int ipc_gprs_port_list_setup(struct ipc_gprs_port_list_data *data)
{
- if (message == NULL)
- return;
+ // FIXME: These are only known-to-work values used on most devices
+ unsigned char magic[] = { 0x02, 0x04, 0x16, 0x00, 0x17, 0x00, 0x87, 0x00, 0xBD, 0x01 };
- memset(message, 0, sizeof(struct ipc_gprs_pdp_context_request_set_data));
+ if (data == NULL)
+ return -1;
- message->enable = enable ? 1 : 0;
- message->cid = cid;
+ memset(data, 0, sizeof(struct ipc_gprs_port_list_data));
+ memcpy(data->magic, magic, sizeof(magic));
- if (enable && username != NULL && password != NULL)
- {
- message->magic[2] = 0x13;
- message->unknown2 = 0x1;
- strncpy((char *) message->username, username, 32);
- strncpy((char *) message->password, password, 32);
- }
+ return 0;
}
// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/misc.c b/samsung-ipc/misc.c
index 27b7341..f36403e 100644
--- a/samsung-ipc/misc.c
+++ b/samsung-ipc/misc.c
@@ -2,6 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
+ * Copyright (C) 2014 Paul Kocialkowski <contact@paulk.fr>
*
* 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
@@ -22,17 +23,26 @@
#include <samsung-ipc.h>
-#define DEFAULT_IMSI_LENGTH 15
-
-char *ipc_misc_me_imsi_response_get_imsi(struct ipc_message_info *response)
+char *ipc_misc_me_imsi_get_imsi(const void *data, size_t size)
{
- if (response == NULL || response->data[0] != DEFAULT_IMSI_LENGTH)
+ struct ipc_misc_me_imsi_header *header;
+ char *imsi;
+ size_t imsi_length;
+
+ if (data == NULL || size < sizeof(struct ipc_misc_me_imsi_header))
return NULL;
- char *buffer = (char *) malloc(sizeof(char) * DEFAULT_IMSI_LENGTH);
- memcpy(buffer, &response->data[1], DEFAULT_IMSI_LENGTH);
+ header = (struct ipc_misc_me_imsi_header *) data;
+
+ // header->length doesn't count the final null character
+ imsi_length = header->length + sizeof(char);
+
+ imsi = (char *) calloc(1, imsi_length);
+
+ strncpy(imsi, (char *) data + sizeof(struct ipc_misc_me_imsi_header), header->length);
+ imsi[header->length] = '\0';
- return buffer;
+ return imsi;
}
// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/net.c b/samsung-ipc/net.c
index e67f909..2d04bc8 100644
--- a/samsung-ipc/net.c
+++ b/samsung-ipc/net.c
@@ -1,7 +1,8 @@
/*
* This file is part of libsamsung-ipc.
*
- * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com
+ * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
+ * Copyright (C) 2014 Paul Kocialkowsk <contact@paulk.fr>
*
* 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
@@ -22,49 +23,47 @@
#include <samsung-ipc.h>
-void ipc_net_regist_setup(struct ipc_net_regist_request_data *message,
- unsigned char domain)
+int ipc_net_plmn_sel_setup(struct ipc_net_plmn_sel_request_data *data,
+ unsigned char mode_sel, const char *plmn, unsigned char act)
{
- message->act = IPC_NET_ACCESS_TECHNOLOGY_UNKNOWN;
- message->domain = domain;
-}
+ size_t plmn_length;
-void ipc_net_plmn_sel_set_setup(struct ipc_net_plmn_sel_request_data *message,
- unsigned char mode, char *plmn, unsigned char act)
-{
- int message_plmn_len;
- int plmn_len;
- int i;
+ if (data == NULL)
+ return -1;
- if (message == NULL)
- return;
+ memset(data, 0, sizeof(struct ipc_net_plmn_sel_request_data));
+ data->mode_sel = mode_sel;
- message_plmn_len = sizeof(message->plmn);
+ if (mode_sel == IPC_NET_PLMN_SEL_AUTO) {
+ data->act = IPC_NET_ACCESS_TECHNOLOGY_UNKNOWN;
+ } else {
+ plmn_length = strlen(plmn);
+ if (plmn_length > sizeof(data->plmn))
+ plmn_length = sizeof(data->plmn);
- memset(message, 0, sizeof(struct ipc_net_plmn_sel_request_data));
+ strncpy((char *) data->plmn, plmn, plmn_length);
+
+ // If there are less (5 is the usual case) PLMN bytes, fill the rest with '#'
+ if (plmn_length < sizeof(data->plmn))
+ memset(data->plmn + plmn_length, '#', sizeof(data->plmn) - plmn_length);
- if (mode == IPC_NET_PLMN_SEL_AUTO)
- {
- message->mode_sel = IPC_NET_PLMN_SEL_AUTO;
- message->act = IPC_NET_ACCESS_TECHNOLOGY_UNKNOWN;
+ data->act = act;
}
- else if (mode == IPC_NET_PLMN_SEL_MANUAL)
- {
- plmn_len = strlen(plmn);
- // Only copy the first (6) bytes if there are more
- if(plmn_len > message_plmn_len)
- plmn_len = message_plmn_len;
+ return 0;
+}
- strncpy(message->plmn, plmn, plmn_len);
+int ipc_net_regist_setup(struct ipc_net_regist_request_data *data,
+ unsigned char domain)
+{
+ if (data == NULL)
+ return -1;
- // If there are less (5 is the usual case) PLMN bytes, fill the rest with '#'
- if (plmn_len < message_plmn_len)
- memset((void *) (message->plmn + plmn_len), '#', message_plmn_len - plmn_len);
+ memset(data, 0, sizeof(struct ipc_net_regist_request_data));
+ data->act = IPC_NET_ACCESS_TECHNOLOGY_UNKNOWN;
+ data->domain = domain;
- message->mode_sel = IPC_NET_PLMN_SEL_MANUAL;
- message->act = act;
- }
+ return 0;
}
// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/sec.c b/samsung-ipc/sec.c
index be26170..9017cb9 100644
--- a/samsung-ipc/sec.c
+++ b/samsung-ipc/sec.c
@@ -2,7 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
- * Copyright (C) 2011 Paul Kocialkowski <contact@paulk.fr>
+ * Copyright (C) 2011-2014 Paul Kocialkowski <contact@paulk.fr>
*
* 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
@@ -23,98 +23,128 @@
#include <samsung-ipc.h>
-void ipc_sec_pin_status_setup(struct ipc_sec_pin_status_request_data *message,
- unsigned char pin_type, char *pin1, char *pin2)
+int ipc_sec_pin_status_setup(struct ipc_sec_pin_status_request_data *data,
+ unsigned char type, const char *pin1, const char *pin2)
{
- if (message == NULL)
- return;
+ size_t pin1_length;
+ size_t pin2_length;
- memset(message, 0, sizeof(struct ipc_sec_pin_status_request_data));
+ if (data == NULL)
+ return -1;
- message->type = pin_type;
+ memset(data, 0, sizeof(struct ipc_sec_pin_status_request_data));
+ data->type = type;
- if (pin1 != NULL)
- {
- strncpy((char *) message->pin1, pin1, 8);
- message->pin1_length = strlen(pin1);
+ if (pin1 != NULL) {
+ pin1_length = strlen(pin1);
+ if (pin1_length > sizeof(data->pin1))
+ pin1_length = sizeof(data->pin1);
+
+ strncpy((char *) data->pin1, pin1, pin1_length);
}
- if (pin2 != NULL)
- {
- strncpy((char *) message->pin2, pin2, 8);
- message->pin2_length = strlen(pin2);
+ if (pin2 != NULL) {
+ pin2_length = strlen(pin2);
+ if (pin2_length > sizeof(data->pin2))
+ pin2_length = sizeof(data->pin2);
+
+ strncpy((char *) data->pin2, pin2, pin2_length);
}
+
+ return 0;
}
-void ipc_sec_lock_infomation_setup(struct ipc_sec_lock_infomation_request_data *message,
- unsigned char pin_type)
+int ipc_sec_phone_lock_request_set_setup(struct ipc_sec_phone_lock_request_set_data *data,
+ unsigned char facility_type, unsigned char active, const char *password)
{
- if (message == NULL)
- return;
+ size_t password_length;
+
+ if (data == NULL)
+ return -1;
+
+ memset(data, 0, sizeof(struct ipc_sec_phone_lock_request_set_data));
+ data->facility_type = facility_type;
+ data->active = active;
+
+ if (password != NULL) {
+ password_length = strlen(password);
+ if (password_length > sizeof(data->password))
+ password_length = sizeof(data->password);
- message->magic = 1;
- message->type = pin_type;
+ data->password_length = (unsigned char) password_length;
+ strncpy((char *) data->password, password, password_length);
+ } else {
+ data->password_length = 0;
+ }
+
+ return 0;
}
-char *ipc_sec_rsim_access_response_get_file_data(struct ipc_message_info *response)
+int ipc_sec_change_locking_pw_setup(struct ipc_sec_change_locking_pw_data *data,
+ unsigned char facility_type, const char *password_old,
+ const char *password_new)
{
- int n = 0;
- int offset = (int) sizeof(struct ipc_sec_rsim_access_response_header);
- int size = 0;
+ size_t password_old_length;
+ size_t password_new_length;
- if (response == NULL)
- return NULL;
+ if (data == NULL)
+ return -1;
- struct ipc_sec_rsim_access_response_header *rsimresp = (struct ipc_sec_rsim_access_response_header*) response->data;
- char *file_data = (char *) malloc(sizeof(char) * rsimresp->length);
-
- for (n = 0; n < rsimresp->length; n++)
- {
- if (response->data[offset + n] == 0x0)
- continue;
- else if (response->data[offset + n] == 0xff)
- break;
- else {
- file_data[size] = response->data[offset + n];
- size++;
- }
+ data->facility_type = facility_type;
+
+ if (password_old != NULL) {
+ password_old_length = strlen(password_old);
+ if (password_old_length > sizeof(data->password_old_length))
+ password_old_length = sizeof(data->password_old_length);
+
+ data->password_old_length = (unsigned char) password_old_length;
+ strncpy((char *) data->password_old, password_old, password_old_length);
+ } else {
+ data->password_old_length = 0;
}
- if (size < rsimresp->length)
- file_data = (char *) realloc(file_data, sizeof(char) * size);
+ if (password_new != NULL) {
+ password_new_length = strlen(password_new);
+ if (password_new_length > sizeof(data->password_new_length))
+ password_new_length = sizeof(data->password_new_length);
- return file_data;
+ data->password_new_length = (unsigned char) password_new_length;
+ strncpy((char *) data->password_new, password_new, password_new_length);
+ } else {
+ data->password_new_length = 0;
+ }
+
+ return 0;
}
-void ipc_sec_phone_lock_request_set_setup(struct ipc_sec_phone_lock_request_set_data *message,
- int pin_type, int enable, char *passwd)
+void *ipc_sec_rsim_access_get_file_data(const void *data, size_t size)
{
- message->facility_type = pin_type;
- message->active = enable ? 1 : 0;
+ struct ipc_sec_rsim_access_response_header *header;
+ void *file_data;
- if (passwd != NULL)
- {
- strncpy((char *) message->password, passwd, 39);
- message->password_length = strlen(passwd);
- }
+ if (data == NULL || size < sizeof(struct ipc_sec_rsim_access_response_header))
+ return NULL;
+
+ header = (struct ipc_sec_rsim_access_response_header *) data;
+
+ file_data = calloc(1, header->length);
+
+ memcpy(file_data, (void *) ((unsigned char *) data + sizeof(struct ipc_sec_rsim_access_response_header)), header->length);
+
+ return file_data;
}
-void ipc_sec_change_locking_pw_setup(struct ipc_sec_change_locking_pw_data *message,
- int type, char *passwd_old, char *passwd_new)
+int ipc_sec_lock_infomation_setup(struct ipc_sec_lock_infomation_request_data *data,
+ unsigned char type)
{
- message->facility_type = type;
+ if (data == NULL)
+ return -1;
- if (passwd_old != NULL)
- {
- strncpy((char *) message->password_old, passwd_old, 39);
- message->password_old_length = strlen(passwd_old);
- }
+ memset(data, 0, sizeof(struct ipc_sec_lock_infomation_request_data));
+ data->magic = 0x01;
+ data->type = type;
- if (passwd_new != NULL)
- {
- strncpy((char *) message->password_new, passwd_new, 39);
- message->password_new_length = strlen(passwd_new);
- }
+ return 0;
}
// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/sms.c b/samsung-ipc/sms.c
index 047754e..bb9e026 100644
--- a/samsung-ipc/sms.c
+++ b/samsung-ipc/sms.c
@@ -2,6 +2,7 @@
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
+ * Copyright (C) 2014 Paul Kocialkowski <contact@paulk.fr>
*
* 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
@@ -22,26 +23,37 @@
#include <samsung-ipc.h>
-unsigned char *ipc_sms_send_msg_pack(struct ipc_sms_send_msg_request_header *msg, char *smsc,
- unsigned char *pdu, int pdu_length)
+void *ipc_sms_send_msg_setup(struct ipc_sms_send_msg_request_header *header,
+ const char *smsc, const char *pdu)
{
- unsigned char *data = NULL, *p = NULL;
- unsigned int data_length = 0, smsc_len = 0;
+ void *data;
+ size_t size;
+ unsigned char smsc_length;
+ unsigned char *p;
- if (msg == NULL || smsc == NULL || pdu == NULL)
+ if (header == NULL || smsc == NULL || pdu == NULL)
return NULL;
- smsc_len = strlen(smsc);
- data_length = smsc_len + pdu_length + sizeof(struct ipc_sms_send_msg_request_header);
- data = (unsigned char *) malloc(sizeof(unsigned char) * data_length);
- memset(data, 0, data_length);
+ smsc_length = (unsigned char) strlen(smsc);
- p = data;
- memcpy(p, msg, sizeof(struct ipc_sms_send_msg_request_header));
+ size = sizeof(struct ipc_sms_send_msg_request_header) + sizeof(smsc_length) + strlen(smsc) + strlen(pdu);
+ header->length = (unsigned char) size;
+
+ data = calloc(1, size);
+
+ p = (unsigned char *) data;
+
+ memcpy(p, header, sizeof(struct ipc_sms_send_msg_request_header));
p += sizeof(struct ipc_sms_send_msg_request_header);
- memcpy(p, (char *) (smsc + 1), smsc_len);
- p += smsc_len;
- memcpy(p, pdu, pdu_length);
+
+ memcpy(p, &smsc_length, sizeof(smsc_length));
+ p += sizeof(smsc_length);
+
+ memcpy(p, smsc, smsc_length);
+ p += smsc_length;
+
+ memcpy(p, pdu, strlen(pdu));
+ p += strlen(pdu);
return data;
}