aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-04-04 19:11:17 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-04-05 17:40:53 +0200
commit48f855176bafd612ec590257a2a5e55b0da7c96d (patch)
tree30ad51e0e3474d0e2394e89c2979c68ac30318e3
parent5b1931e6c62146ea53c987a6a45d3570abd1bd18 (diff)
downloadhardware_replicant_libsamsung-ipc-48f855176bafd612ec590257a2a5e55b0da7c96d.tar.gz
hardware_replicant_libsamsung-ipc-48f855176bafd612ec590257a2a5e55b0da7c96d.tar.bz2
hardware_replicant_libsamsung-ipc-48f855176bafd612ec590257a2a5e55b0da7c96d.zip
samsung-ipc: sec: switch to Linux code style
This contains no functional changes. The commented out code if any has also been preserved as it could be relevant to the understanding of the code. It will be kept until we understand why the code has been commented. In that case we either need to remove it completely or to replace it by a comment explaining why not having that code was necessary. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--samsung-ipc/sec.c292
1 files changed, 157 insertions, 135 deletions
diff --git a/samsung-ipc/sec.c b/samsung-ipc/sec.c
index 9919592..4403d82 100644
--- a/samsung-ipc/sec.c
+++ b/samsung-ipc/sec.c
@@ -24,192 +24,214 @@
#include <samsung-ipc.h>
int ipc_sec_pin_status_setup(struct ipc_sec_pin_status_request_data *data,
- unsigned char type, const char *pin1, const char *pin2)
+ unsigned char type, const char *pin1,
+ const char *pin2)
{
- size_t pin1_length;
- size_t pin2_length;
+ size_t pin1_length;
+ size_t pin2_length;
- if (data == NULL)
- return -1;
+ if (data == NULL)
+ return -1;
- memset(data, 0, sizeof(struct ipc_sec_pin_status_request_data));
- data->type = type;
+ memset(data, 0, sizeof(struct ipc_sec_pin_status_request_data));
+ data->type = type;
- if (pin1 != NULL) {
- pin1_length = strlen(pin1);
- if (pin1_length > sizeof(data->pin1))
- pin1_length = sizeof(data->pin1);
+ if (pin1 != NULL) {
+ pin1_length = strlen(pin1);
+ if (pin1_length > sizeof(data->pin1)) {
+ pin1_length = sizeof(data->pin1);
+ }
- data->pin1_length = (unsigned char) pin1_length;
- strncpy((char *) data->pin1, pin1, pin1_length);
- }
+ data->pin1_length = (unsigned char) pin1_length;
+ strncpy((char *) data->pin1, pin1, pin1_length);
+ }
- if (pin2 != NULL) {
- pin2_length = strlen(pin2);
- if (pin2_length > sizeof(data->pin2))
- pin2_length = sizeof(data->pin2);
+ if (pin2 != NULL) {
+ pin2_length = strlen(pin2);
+ if (pin2_length > sizeof(data->pin2)) {
+ pin2_length = sizeof(data->pin2);
+ }
- data->pin2_length = (unsigned char) pin2_length;
- strncpy((char *) data->pin2, pin2, pin2_length);
- }
+ data->pin2_length = (unsigned char) pin2_length;
+ strncpy((char *) data->pin2, pin2, pin2_length);
+ }
- return 0;
+ return 0;
}
-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_phone_lock_request_set_setup(
+ struct ipc_sec_phone_lock_request_set_data *data,
+ unsigned char facility_type, unsigned char active, const char *password)
{
- size_t password_length;
+ size_t password_length;
- if (data == NULL)
- return -1;
+ 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;
+ 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);
+ if (password != NULL) {
+ password_length = strlen(password);
+ if (password_length > sizeof(data->password)) {
+ password_length = sizeof(data->password);
+ }
- data->password_length = (unsigned char) password_length;
- strncpy((char *) data->password, password, password_length);
- } else {
- data->password_length = 0;
- }
+ data->password_length = (unsigned char) password_length;
+ strncpy((char *) data->password, password, password_length);
+ } else {
+ data->password_length = 0;
+ }
- return 0;
+ return 0;
}
-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 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)
{
- size_t password_old_length;
- size_t password_new_length;
-
- if (data == NULL)
- return -1;
-
- memset(data, 0, sizeof(struct ipc_sec_change_locking_pw_data));
- data->facility_type = facility_type;
-
- if (password_old != NULL) {
- password_old_length = strlen(password_old);
- if (password_old_length > sizeof(data->password_old))
- password_old_length = sizeof(data->password_old);
-
- 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 (password_new != NULL) {
- password_new_length = strlen(password_new);
- if (password_new_length > sizeof(data->password_new))
- password_new_length = sizeof(data->password_new);
-
- 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;
+ size_t password_old_length;
+ size_t password_new_length;
+
+ if (data == NULL)
+ return -1;
+
+ memset(data, 0, sizeof(struct ipc_sec_change_locking_pw_data));
+ data->facility_type = facility_type;
+
+ if (password_old != NULL) {
+ password_old_length = strlen(password_old);
+ if (password_old_length > sizeof(data->password_old)) {
+ password_old_length = sizeof(data->password_old);
+ }
+
+ 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 (password_new != NULL) {
+ password_new_length = strlen(password_new);
+ if (password_new_length > sizeof(data->password_new)) {
+ password_new_length = sizeof(data->password_new);
+ }
+
+ 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;
}
-size_t ipc_sec_rsim_access_size_setup(struct ipc_sec_rsim_access_request_header *header,
- const void *sim_io_data, size_t sim_io_size)
+size_t ipc_sec_rsim_access_size_setup(
+ struct ipc_sec_rsim_access_request_header *header,
+ const void *sim_io_data, size_t sim_io_size)
{
- size_t size;
+ size_t size;
- if (header == NULL)
- return 0;
+ if (header == NULL)
+ return 0;
- if (sim_io_data == NULL)
- sim_io_size = 0;
+ if (sim_io_data == NULL)
+ sim_io_size = 0;
- size = sizeof(struct ipc_sec_rsim_access_request_header) + sim_io_size;
+ size = sizeof(struct ipc_sec_rsim_access_request_header) + sim_io_size;
- return size;
+ return size;
}
-void *ipc_sec_rsim_access_setup(struct ipc_sec_rsim_access_request_header *header,
- const void *sim_io_data, size_t sim_io_size)
+void *ipc_sec_rsim_access_setup(
+ struct ipc_sec_rsim_access_request_header *header,
+ const void *sim_io_data, size_t sim_io_size)
{
- void *data;
- size_t size;
- unsigned char *p;
+ void *data;
+ size_t size;
+ unsigned char *p;
- if (header == NULL)
- return NULL;
+ if (header == NULL)
+ return NULL;
- if (sim_io_data == NULL)
- sim_io_size = 0;
+ if (sim_io_data == NULL)
+ sim_io_size = 0;
- size = ipc_sec_rsim_access_size_setup(header, sim_io_data, sim_io_size);
- if (size == 0)
- return NULL;
+ size = ipc_sec_rsim_access_size_setup(header, sim_io_data, sim_io_size);
+ if (size == 0)
+ return NULL;
- data = calloc(1, size);
+ data = calloc(1, size);
- p = (unsigned char *) data;
+ p = (unsigned char *) data;
- memcpy(p, header, sizeof(struct ipc_sec_rsim_access_request_header));
- p += sizeof(struct ipc_sec_rsim_access_request_header);
+ memcpy(p, header, sizeof(struct ipc_sec_rsim_access_request_header));
+ p += sizeof(struct ipc_sec_rsim_access_request_header);
- if (sim_io_data != NULL && sim_io_size > 0) {
- memcpy(p, sim_io_data, sim_io_size);
- p += sim_io_size;
- }
+ if (sim_io_data != NULL && sim_io_size > 0) {
+ memcpy(p, sim_io_data, sim_io_size);
+ p += sim_io_size;
+ }
- return data;
+ return data;
}
size_t ipc_sec_rsim_access_size_extract(const void *data, size_t size)
{
- struct ipc_sec_rsim_access_response_header *header;
+ struct ipc_sec_rsim_access_response_header *header;
- if (data == NULL || size < sizeof(struct ipc_sec_rsim_access_response_header))
- return 0;
+ if (data == NULL ||
+ size < sizeof(struct ipc_sec_rsim_access_response_header)) {
+ return 0;
+ }
- header = (struct ipc_sec_rsim_access_response_header *) data;
- if (header->length == 0 || header->length > size - sizeof(struct ipc_sec_rsim_access_response_header))
- return 0;
+ header = (struct ipc_sec_rsim_access_response_header *) data;
+ if (header->length == 0 ||
+ header->length > size -
+ sizeof(struct ipc_sec_rsim_access_response_header)) {
+ return 0;
+ }
- return (size_t) header->length;
+ return (size_t) header->length;
}
void *ipc_sec_rsim_access_extract(const void *data, size_t size)
{
- struct ipc_sec_rsim_access_response_header *header;
- void *rsim_data;
-
- if (data == NULL || size < sizeof(struct ipc_sec_rsim_access_response_header))
- return NULL;
-
- header = (struct ipc_sec_rsim_access_response_header *) data;
- if (header->length == 0 || header->length > size - sizeof(struct ipc_sec_rsim_access_response_header))
- return NULL;
-
- rsim_data = (void *) ((unsigned char *) data + sizeof(struct ipc_sec_rsim_access_response_header));
-
- return rsim_data;
+ struct ipc_sec_rsim_access_response_header *header;
+ void *rsim_data;
+
+ if (data == NULL ||
+ size < sizeof(struct ipc_sec_rsim_access_response_header)) {
+ }
+ return NULL;
+
+ header = (struct ipc_sec_rsim_access_response_header *) data;
+ if (header->length == 0 ||
+ header->length > size -
+ sizeof(struct ipc_sec_rsim_access_response_header)) {
+ return NULL;
+ }
+
+ rsim_data = (void *) (
+ (unsigned char *) data +
+ sizeof(struct ipc_sec_rsim_access_response_header));
+
+ return rsim_data;
}
-int ipc_sec_lock_infomation_setup(struct ipc_sec_lock_infomation_request_data *data,
- unsigned char type)
+int ipc_sec_lock_infomation_setup(
+ struct ipc_sec_lock_infomation_request_data *data, unsigned char type)
{
- if (data == NULL)
- return -1;
+ if (data == NULL)
+ return -1;
- memset(data, 0, sizeof(struct ipc_sec_lock_infomation_request_data));
- data->magic = 0x01;
- data->type = type;
+ memset(data, 0, sizeof(struct ipc_sec_lock_infomation_request_data));
+ data->magic = 0x01;
+ data->type = type;
- return 0;
+ return 0;
}
-
-// vim:ts=4:sw=4:expandtab