aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2013-06-25 22:18:41 +0200
committerPaul Kocialkowski <contact@paulk.fr>2013-06-25 22:18:41 +0200
commitc9dfae7a17ea4e5a2e114df331942f70d48bfe5b (patch)
treeecb078dd2e97ec1f2d56ae99da54f6d3028015d1 /samsung-ipc
parent0e0c698a13ae658640af085591b809bbc9a6f658 (diff)
downloadhardware_replicant_libsamsung-ipc-c9dfae7a17ea4e5a2e114df331942f70d48bfe5b.tar.gz
hardware_replicant_libsamsung-ipc-c9dfae7a17ea4e5a2e114df331942f70d48bfe5b.tar.bz2
hardware_replicant_libsamsung-ipc-c9dfae7a17ea4e5a2e114df331942f70d48bfe5b.zip
Refactor code for consistent coding style and avoid using assert
Change-Id: Idca5edb70869e07d35744301b185df02e42f5b4c Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'samsung-ipc')
-rw-r--r--samsung-ipc/call.c89
-rw-r--r--samsung-ipc/gen.c5
-rw-r--r--samsung-ipc/gprs.c21
-rw-r--r--samsung-ipc/ipc.c5
-rw-r--r--samsung-ipc/ipc.h2
-rw-r--r--samsung-ipc/ipc_devices.c2
-rw-r--r--samsung-ipc/ipc_devices.h2
-rw-r--r--samsung-ipc/ipc_util.c2
-rw-r--r--samsung-ipc/misc.c12
-rw-r--r--samsung-ipc/net.c13
-rw-r--r--samsung-ipc/rfs.c6
-rw-r--r--samsung-ipc/sec.c29
-rw-r--r--samsung-ipc/sms.c17
-rw-r--r--samsung-ipc/wakelock.c18
14 files changed, 117 insertions, 106 deletions
diff --git a/samsung-ipc/call.c b/samsung-ipc/call.c
index a12bbde..ee7ef89 100644
--- a/samsung-ipc/call.c
+++ b/samsung-ipc/call.c
@@ -1,6 +1,7 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
+ * Copyright (C) 2013 Paul Kocialkowsk <contact@paulk.fr>
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
*
* libsamsung-ipc is free software: you can redistribute it and/or modify
@@ -18,112 +19,102 @@
*
*/
-#include <samsung-ipc.h>
-#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+#include <string.h>
-#define OUTGOING_NUMBER_MAX_LENGTH 86
+#include <samsung-ipc.h>
+
+#define OUTGOING_NUMBER_MAX_LENGTH 86
-void ipc_call_outgoing_setup(struct ipc_call_outgoing *message, unsigned char type,
- unsigned char identity, unsigned char prefix, char *number)
+void ipc_call_outgoing_setup(struct ipc_call_outgoing *message, unsigned char type, unsigned char identity, unsigned char prefix, char *number)
{
- assert(message != NULL);
+ int length;
+
+ if (message == NULL || number == NULL)
+ return;
+
+ length = strlen(number);
+ if (length > OUTGOING_NUMBER_MAX_LENGTH)
+ length = OUTGOING_NUMBER_MAX_LENGTH;
memset(message, 0, sizeof(struct ipc_call_outgoing));
message->type = type;
message->identity = identity;
message->prefix = prefix;
- message->length = strlen(number);
-
- assert(message->length <= OUTGOING_NUMBER_MAX_LENGTH);
+ message->length = length;
- strncpy(message->number, number, message->length);
+ strncpy((char *) message->number, number, length);
}
-/**
- * Retrieve number of calls in list of calls.
- **/
+/* Retrieve number of calls in list of calls */
unsigned int ipc_call_list_response_get_num_entries(struct ipc_message_info *response)
{
- unsigned int count = 0, n = 0;
-
- assert(response != NULL);
- assert(response->data != NULL);
+ if (response == NULL || response->data == NULL || response->length < sizeof(unsigned int))
+ return 0;
- count = (unsigned int) *((unsigned char*) response->data);
- return count;
+ return *((unsigned int *) response->data);
}
-/**
- * Retrieve one specific entry from a list of calls.
- **/
+/* 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)
{
- unsigned int count = 0, pos = 1, n = 0;
+ unsigned int count, pos, n;
struct ipc_call_list_entry *entry = NULL;
- assert(response != NULL);
- assert(response->data != NULL);
-
count = ipc_call_list_response_get_num_entries(response);
- if (num > count)
+ if (num > count || count == 0)
return NULL;
+ pos = 1;
for (n = 0; n < num + 1; n++)
{
- entry = (struct ipc_call_list_entry*) (response->data + pos);
+ entry = (struct ipc_call_list_entry *) (response->data + pos);
pos += (unsigned int) (sizeof(struct ipc_call_list_entry) + entry->number_len);
}
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)
+/* 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)
{
- unsigned int count = 0, pos = 1, n = 0;
+ unsigned int count, pos, n;
struct ipc_call_list_entry *entry = NULL;
- char *number = NULL;
-
- assert(response != NULL);
- assert(response->data != NULL);
+ char *number;
count = ipc_call_list_response_get_num_entries(response);
- if (num > count)
+ if (num > count || count == 0)
return NULL;
+ pos = 1;
for (n = 0; n < num + 1; n++)
{
if (entry != NULL)
pos += entry->number_len;
- entry = (struct ipc_call_list_entry*) (response->data + pos);
+ entry = (struct ipc_call_list_entry *) (response->data + pos);
pos += (unsigned int) sizeof(struct ipc_call_list_entry);
}
- if (entry == NULL || (unsigned char*) (response->data + pos) == NULL)
+ if (entry == NULL || (unsigned char *) (response->data + pos) == NULL)
return NULL;
- number = (char*) malloc(sizeof(char) * entry->number_len);
- strncpy(number, response->data + pos, entry->number_len);
+ number = (char *) malloc(sizeof(char) * entry->number_len);
+ strncpy(number, (char *) (response->data + pos), entry->number_len);
return number;
}
-unsigned char* ipc_call_cont_dtmf_burst_pack(struct ipc_call_cont_dtmf *message, unsigned char *burst, int burst_len)
+unsigned char *ipc_call_cont_dtmf_burst_pack(struct ipc_call_cont_dtmf *message, unsigned char *burst, int burst_len)
{
unsigned char *data = NULL;
int data_len = sizeof(struct ipc_call_cont_dtmf) + burst_len;
- assert(message != 0);
- assert(burst != 0);
- assert(burst_len != 0);
+ if (message == NULL || burst == NULL || burst_len <= 0)
+ return NULL;
- data = (unsigned char*) malloc(sizeof(unsigned char) * data_len);
+ data = (unsigned char *) malloc(sizeof(unsigned char) * data_len);
memset(data, 0, data_len);
memcpy(data, message, sizeof(struct ipc_call_cont_dtmf));
diff --git a/samsung-ipc/gen.c b/samsung-ipc/gen.c
index 26af233..ffdf51d 100644
--- a/samsung-ipc/gen.c
+++ b/samsung-ipc/gen.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Paul Kocialkowsk <contact@paulk.fr>
@@ -18,7 +18,8 @@
*
*/
-#include <stdio.h>
+#include <stdlib.h>
+
#include <samsung-ipc.h>
int ipc_gen_phone_res_check(struct ipc_gen_phone_res *res)
diff --git a/samsung-ipc/gprs.c b/samsung-ipc/gprs.c
index bb87674..59b5c97 100644
--- a/samsung-ipc/gprs.c
+++ b/samsung-ipc/gprs.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
@@ -18,10 +18,10 @@
*
*/
-#include <samsung-ipc.h>
-#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+#include <string.h>
+
+#include <samsung-ipc.h>
void ipc_gprs_port_list_setup(struct ipc_gprs_port_list *message)
{
@@ -30,7 +30,8 @@ void ipc_gprs_port_list_setup(struct ipc_gprs_port_list *message)
0x02, 0x04, 0x16, 0x00, 0x17, 0x00, 0x87, 0x00, 0xBD, 0x01
};
- assert(message != NULL);
+ if (message == NULL)
+ return;
memset(message, 0, sizeof(struct ipc_gprs_port_list));
@@ -40,7 +41,8 @@ void ipc_gprs_port_list_setup(struct ipc_gprs_port_list *message)
void ipc_gprs_define_pdp_context_setup(struct ipc_gprs_define_pdp_context *message,
unsigned char cid, int enable, char *apn)
{
- assert(message != NULL);
+ if (message == NULL)
+ return;
memset(message, 0, sizeof(struct ipc_gprs_define_pdp_context));
@@ -54,7 +56,8 @@ void ipc_gprs_define_pdp_context_setup(struct ipc_gprs_define_pdp_context *messa
void ipc_gprs_pdp_context_setup(struct ipc_gprs_pdp_context_set *message,
unsigned char cid, int enable, char *username, char *password)
{
- assert(message != NULL);
+ if (message == NULL)
+ return;
memset(message, 0, sizeof(struct ipc_gprs_pdp_context_set));
@@ -65,8 +68,8 @@ void ipc_gprs_pdp_context_setup(struct ipc_gprs_pdp_context_set *message,
{
message->unk0[2] = 0x13;
message->unk2 = 0x1;
- strncpy((char*)message->username, username, 32);
- strncpy((char*)message->password, password, 32);
+ strncpy((char *) message->username, username, 32);
+ strncpy((char *) message->password, password, 32);
}
}
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index 7225901..028e930 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -1,8 +1,8 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
+ * Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
- * 2011 Simon Busch <morphis@gravedo.de>
*
* 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,7 +22,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <assert.h>
#include <stdint.h>
#include <stdarg.h>
#include <unistd.h>
diff --git a/samsung-ipc/ipc.h b/samsung-ipc/ipc.h
index 98d7935..d52e949 100644
--- a/samsung-ipc/ipc.h
+++ b/samsung-ipc/ipc.h
@@ -67,7 +67,7 @@ struct ipc_handlers {
};
struct ipc_gprs_specs {
- char* (*gprs_get_iface)(int cid);
+ char *(*gprs_get_iface)(int cid);
int (*gprs_get_capabilities)(struct ipc_client_gprs_capabilities *cap);
};
diff --git a/samsung-ipc/ipc_devices.c b/samsung-ipc/ipc_devices.c
index c82374a..95f6455 100644
--- a/samsung-ipc/ipc_devices.c
+++ b/samsung-ipc/ipc_devices.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
diff --git a/samsung-ipc/ipc_devices.h b/samsung-ipc/ipc_devices.h
index 0e600ca..8c7dc95 100644
--- a/samsung-ipc/ipc_devices.h
+++ b/samsung-ipc/ipc_devices.h
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
diff --git a/samsung-ipc/ipc_util.c b/samsung-ipc/ipc_util.c
index 249f2e2..f8ca088 100644
--- a/samsung-ipc/ipc_util.c
+++ b/samsung-ipc/ipc_util.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
diff --git a/samsung-ipc/misc.c b/samsung-ipc/misc.c
index 96798cf..9241453 100644
--- a/samsung-ipc/misc.c
+++ b/samsung-ipc/misc.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
@@ -17,19 +17,21 @@
* along with libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
*
*/
+#include <stdlib.h>
+#include <string.h>
#include <samsung-ipc.h>
-#include <string.h>
-#define DEFAULT_IMSI_LENGTH 15
+#define DEFAULT_IMSI_LENGTH 15
-char* ipc_misc_me_imsi_response_get_imsi(struct ipc_message_info *response)
+char *ipc_misc_me_imsi_response_get_imsi(struct ipc_message_info *response)
{
if (response == NULL || response->data[0] != DEFAULT_IMSI_LENGTH)
return NULL;
- char *buffer = (char*) malloc(sizeof(char) * DEFAULT_IMSI_LENGTH);
+ char *buffer = (char *) malloc(sizeof(char) * DEFAULT_IMSI_LENGTH);
memcpy(buffer, &response->data[1], DEFAULT_IMSI_LENGTH);
+
return buffer;
}
diff --git a/samsung-ipc/net.c b/samsung-ipc/net.c
index 8e1df03..7164565 100644
--- a/samsung-ipc/net.c
+++ b/samsung-ipc/net.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com
@@ -18,7 +18,9 @@
*
*/
+#include <stdlib.h>
#include <string.h>
+
#include <samsung-ipc.h>
void ipc_net_regist_get_setup(struct ipc_net_regist_get *message, unsigned char domain)
@@ -30,10 +32,15 @@ void ipc_net_regist_get_setup(struct ipc_net_regist_get *message, unsigned char
void ipc_net_plmn_sel_set_setup(struct ipc_net_plmn_sel_set *message, unsigned char mode, char *plmn, unsigned char act)
{
- int message_plmn_len = sizeof(message->plmn) / sizeof(char);
+ int message_plmn_len;
int plmn_len;
int i;
+ if (message == NULL)
+ return;
+
+ message_plmn_len = sizeof(message->plmn);
+
memset(message, 0, sizeof(struct ipc_net_plmn_sel_set));
if (mode == IPC_NET_PLMN_SEL_AUTO)
@@ -53,7 +60,7 @@ void ipc_net_plmn_sel_set_setup(struct ipc_net_plmn_sel_set *message, unsigned c
// 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((void *) (message->plmn + plmn_len), '#', message_plmn_len - plmn_len);
message->mode = IPC_NET_PLMN_SEL_MANUAL;
message->act = act;
diff --git a/samsung-ipc/rfs.c b/samsung-ipc/rfs.c
index 7075bd1..04426ec 100644
--- a/samsung-ipc/rfs.c
+++ b/samsung-ipc/rfs.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Paul Kocialkowski <contact@paulk.fr>
@@ -867,7 +867,7 @@ void ipc_rfs_send_io_confirm_for_nv_read_item(struct ipc_client *client, struct
rfs_io_conf->offset = rfs_io->offset;
rfs_io_conf->length = rfs_io->length;
- ipc_client_send(client, IPC_RFS_NV_READ_ITEM, 0, (unsigned char*) rfs_io_conf,
+ ipc_client_send(client, IPC_RFS_NV_READ_ITEM, 0, (unsigned char *) rfs_io_conf,
rfs_io->length + sizeof(struct ipc_rfs_io_confirm), info->aseq);
free(rfs_io_conf);
}
@@ -901,7 +901,7 @@ void ipc_rfs_send_io_confirm_for_nv_write_item(struct ipc_client *client, struct
rfs_io_conf->offset = rfs_io->offset;
rfs_io_conf->length = rfs_io->length;
- ipc_client_send(client, IPC_RFS_NV_WRITE_ITEM, 0, (unsigned char*) rfs_io_conf,
+ ipc_client_send(client, IPC_RFS_NV_WRITE_ITEM, 0, (unsigned char *) rfs_io_conf,
sizeof(struct ipc_rfs_io_confirm), info->aseq);
free(rfs_io_conf);
}
diff --git a/samsung-ipc/sec.c b/samsung-ipc/sec.c
index 7205936..933398b 100644
--- a/samsung-ipc/sec.c
+++ b/samsung-ipc/sec.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
@@ -19,29 +19,30 @@
*
*/
-#include <samsung-ipc.h>
-#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+#include <string.h>
+
+#include <samsung-ipc.h>
void ipc_sec_pin_status_set_setup(struct ipc_sec_pin_status_set *message,
unsigned char pin_type, char *pin1, char *pin2)
{
- assert(message != NULL);
+ if (message == NULL)
+ return;
- memset(message, 0, sizeof(struct ipc_sec_pin_status_set));
+ memset(message, 0, sizeof(struct ipc_sec_pin_status_set));
message->type = pin_type;
if (pin1 != NULL)
{
- strncpy((char*)message->pin1, pin1, 8);
+ strncpy((char *) message->pin1, pin1, 8);
message->length1 = strlen(pin1);
}
if (pin2 != NULL)
{
- strncpy((char*)message->pin2, pin2, 8);
+ strncpy((char *) message->pin2, pin2, 8);
message->length2 = strlen(pin2);
}
}
@@ -56,7 +57,7 @@ void ipc_sec_lock_info_get_setup(struct ipc_sec_lock_info_get *message,
message->pin_type = pin_type;
}
-char* ipc_sec_rsim_access_response_get_file_data(struct ipc_message_info *response)
+char *ipc_sec_rsim_access_response_get_file_data(struct ipc_message_info *response)
{
int n = 0;
int offset = (int) sizeof(struct ipc_sec_rsim_access_response);
@@ -66,7 +67,7 @@ char* ipc_sec_rsim_access_response_get_file_data(struct ipc_message_info *respon
return NULL;
struct ipc_sec_rsim_access_response *rsimresp = (struct ipc_sec_rsim_access_response*) response->data;
- char *file_data = (char*) malloc(sizeof(char) * rsimresp->len);
+ char *file_data = (char *) malloc(sizeof(char) * rsimresp->len);
for (n = 0; n < rsimresp->len; n++)
{
@@ -81,7 +82,7 @@ char* ipc_sec_rsim_access_response_get_file_data(struct ipc_message_info *respon
}
if (size < rsimresp->len)
- file_data = (char*) realloc(file_data, sizeof(char) * size);
+ file_data = (char *) realloc(file_data, sizeof(char) * size);
return file_data;
}
@@ -94,7 +95,7 @@ void ipc_sec_phone_lock_set_setup(struct ipc_sec_phone_lock_set *message,
if (passwd != NULL)
{
- strncpy((char*) message->password, passwd, 39);
+ strncpy((char *) message->password, passwd, 39);
message->length = strlen(passwd);
}
}
@@ -106,13 +107,13 @@ void ipc_sec_change_locking_pw_set_setup(struct ipc_sec_change_locking_pw_set *m
if (passwd_old != NULL)
{
- strncpy((char*) message->password_old, passwd_old, 39);
+ strncpy((char *) message->password_old, passwd_old, 39);
message->length_old = strlen(passwd_old);
}
if (passwd_new != NULL)
{
- strncpy((char*) message->password_new, passwd_new, 39);
+ strncpy((char *) message->password_new, passwd_new, 39);
message->length_new = strlen(passwd_new);
}
}
diff --git a/samsung-ipc/sms.c b/samsung-ipc/sms.c
index a4c7855..8b91987 100644
--- a/samsung-ipc/sms.c
+++ b/samsung-ipc/sms.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
@@ -18,28 +18,29 @@
*
*/
-#include <samsung-ipc.h>
+#include <stdlib.h>
#include <string.h>
-#include <assert.h>
-unsigned char* ipc_sms_send_msg_pack(struct ipc_sms_send_msg_request *msg, char *smsc,
+#include <samsung-ipc.h>
+
+unsigned char *ipc_sms_send_msg_pack(struct ipc_sms_send_msg_request *msg, char *smsc,
unsigned char *pdu, int pdu_length)
{
unsigned char *data = NULL, *p = NULL;
unsigned int data_length = 0, smsc_len = 0;
- assert(smsc != NULL);
- assert(pdu != NULL);
+ if (msg == NULL || smsc == NULL || pdu == NULL)
+ return NULL;
smsc_len = strlen(smsc);
data_length = smsc_len + pdu_length + sizeof(struct ipc_sms_send_msg_request);
- data = (unsigned char*) malloc(sizeof(unsigned char) * data_length);
+ data = (unsigned char *) malloc(sizeof(unsigned char) * data_length);
memset(data, 0, data_length);
p = data;
memcpy(p, msg, sizeof(struct ipc_sms_send_msg_request));
p += sizeof(struct ipc_sms_send_msg_request);
- memcpy(p, (char*) (smsc + 1), smsc_len);
+ memcpy(p, (char *) (smsc + 1), smsc_len);
p += smsc_len;
memcpy(p, pdu, pdu_length);
diff --git a/samsung-ipc/wakelock.c b/samsung-ipc/wakelock.c
index 5946809..2e42671 100644
--- a/samsung-ipc/wakelock.c
+++ b/samsung-ipc/wakelock.c
@@ -1,4 +1,4 @@
-/**
+/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2012 Alexander Tarasikov <alexander.tarasikov@gmail.com>
@@ -18,11 +18,11 @@
*
*/
-#include <assert.h>
-#include <fcntl.h>
-#include <wakelock.h>
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
+
+#include <wakelock.h>
static int wake_lock_fd = -1;
static int wake_unlock_fd = -1;
@@ -30,7 +30,9 @@ static int wake_unlock_fd = -1;
int wake_lock(char *lock_name)
{
int rc;
- assert(lock_name != NULL);
+
+ if (lock_name == NULL)
+ return -1;
if (wake_lock_fd < 0)
wake_lock_fd = open("/sys/power/wake_lock", O_RDWR);
@@ -46,7 +48,9 @@ int wake_lock(char *lock_name)
int wake_unlock(char *lock_name)
{
int rc;
- assert(lock_name != NULL);
+
+ if (lock_name == NULL)
+ return -1;
if (wake_unlock_fd < 0)
wake_unlock_fd = open("/sys/power/wake_unlock", O_RDWR);
@@ -58,3 +62,5 @@ int wake_unlock(char *lock_name)
return rc;
}
+
+// vim:ts=4:sw=4:expandtab