From d3b36a6ae184d4e41ba815e6a49fa223e466ecb9 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Sat, 4 Oct 2014 20:59:36 +0200 Subject: samsung-ril-socket: SRS test messages implementation Signed-off-by: Paul Kocialkowski --- Android.mk | 16 +++++ include/samsung-ril-socket.h | 7 ++ samsung-ril.c | 4 ++ srs.c | 17 +++++ srs.h | 1 + tools/srs-test.c | 149 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 194 insertions(+) create mode 100644 tools/srs-test.c diff --git a/Android.mk b/Android.mk index 29f0c24..993d3fb 100644 --- a/Android.mk +++ b/Android.mk @@ -71,3 +71,19 @@ LOCAL_MODULE_TAGS := optional LOCAL_MODULE := libsrs-client include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := tools/srs-test.c + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/include \ + $(LOCAL_PATH)/srs-client/include \ + +LOCAL_SHARED_LIBRARIES := liblog libcutils libsrs-client + +LOCAL_PRELINK_MODULE := false +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := srs-test + +include $(BUILD_EXECUTABLE) diff --git a/include/samsung-ril-socket.h b/include/samsung-ril-socket.h index 9e919d1..8282727 100644 --- a/include/samsung-ril-socket.h +++ b/include/samsung-ril-socket.h @@ -28,6 +28,7 @@ #define SRS_GROUP_CONTROL 0x01 #define SRS_GROUP_SND 0x02 +#define SRS_GROUP_TEST 0x03 /* * Commands @@ -39,6 +40,8 @@ #define SRS_SND_SET_CALL_AUDIO_PATH 0x0202 #define SRS_SND_SET_CALL_CLOCK_SYNC 0x0203 +#define SRS_TEST_SET_RADIO_STATE 0x0301 + /* * Values */ @@ -110,4 +113,8 @@ struct srs_snd_call_clock_sync_data { unsigned char sync; } __attribute__((__packed__)); +struct srs_test_set_radio_state_data { + int state; +} __attribute__((__packed__)); + #endif diff --git a/samsung-ril.c b/samsung-ril.c index 43784a7..5b191fd 100644 --- a/samsung-ril.c +++ b/samsung-ril.c @@ -237,6 +237,10 @@ struct srs_dispatch_handler srs_dispatch_handlers[] = { .command = SRS_SND_SET_CALL_CLOCK_SYNC, .handler = srs_snd_set_call_clock_sync, }, + { + .command = SRS_TEST_SET_RADIO_STATE, + .handler = srs_test_set_radio_state, + }, }; unsigned int srs_dispatch_handlers_count = sizeof(srs_dispatch_handlers) / diff --git a/srs.c b/srs.c index 890a33e..5cca71c 100644 --- a/srs.c +++ b/srs.c @@ -55,6 +55,8 @@ const char *srs_command_string(unsigned short command) return "SRS_SND_SET_CALL_AUDIO_PATH"; case SRS_SND_SET_CALL_CLOCK_SYNC: return "SRS_SND_SET_CALL_CLOCK_SYNC"; + case SRS_TEST_SET_RADIO_STATE: + return "SRS_TEST_SET_RADIO_STATE"; default: snprintf((char *) &command_string, sizeof(command_string), "0x%04x", command); return command_string; @@ -184,6 +186,21 @@ int srs_control_ping(struct srs_message *message) return 0; } +int srs_test_set_radio_state(struct srs_message *message) +{ + struct srs_test_set_radio_state_data *data; + int rc; + + if (message == NULL || message->data == NULL || message->size < sizeof(struct srs_test_set_radio_state_data)) + return -1; + + data = (struct srs_test_set_radio_state_data *) message->data; + + ril_radio_state_update((RIL_RadioState) data->state); + + return 0; +} + /* * SRS client */ diff --git a/srs.h b/srs.h index 5dfb4f3..bc07591 100644 --- a/srs.h +++ b/srs.h @@ -74,6 +74,7 @@ int srs_message_setup(const struct srs_header *header, /* SRS */ int srs_send(unsigned short command, const void *data, size_t size); int srs_control_ping(struct srs_message *message); +int srs_test_set_radio_state(struct srs_message *message); /* SRS client */ int srs_client_register(struct ril_client *ril_client, int fd); diff --git a/tools/srs-test.c b/tools/srs-test.c new file mode 100644 index 0000000..ac91f1a --- /dev/null +++ b/tools/srs-test.c @@ -0,0 +1,149 @@ +/* + * This file is part of Samsung-RIL. + * + * Copyright (C) 2014 Paul Kocialkowski + * + * Samsung-RIL 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. + * + * Samsung-RIL 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 Samsung-RIL. If not, see . + */ + +#include +#include +#include + +#include + +#include +#include + +struct radio_state_string { + char *string; + RIL_RadioState state; +}; + +void display_help(void) +{ + printf("Usage: srs-test [COMMAND]\n"); + printf("\n"); + printf("Commands:\n"); + printf(" radio-state [STATE] - set radio state\n"); + printf("\n"); + printf("States: off, unavailable, sim-not-ready, sim-locked-absent, sim-ready, on\n"); +} + +int radio_state(struct srs_client *client, char *string) +{ + struct radio_state_string radio_state_strings[] = { + { "off", RADIO_STATE_OFF }, + { "unavailable", RADIO_STATE_UNAVAILABLE }, + { "sim-not-ready", RADIO_STATE_SIM_NOT_READY }, + { "sim-locked-absent", RADIO_STATE_SIM_LOCKED_OR_ABSENT }, + { "sim-ready", RADIO_STATE_SIM_READY }, + { "on", RADIO_STATE_ON }, + }; + struct srs_test_set_radio_state_data data; + RIL_RadioState state = 0; + unsigned int count; + unsigned int i; + int rc; + + if (client == NULL || string == NULL) + return -1; + + count = sizeof(radio_state_strings) / sizeof(struct radio_state_string); + + for (i = 0; i < count; i++) { + if (radio_state_strings[i].string == NULL) + break; + + if (strcmp(radio_state_strings[i].string, string) == 0) { + state = radio_state_strings[i].state; + break; + } + } + + if (i >= count) + return -1; + + printf("%s: Setting radio state to %s\n", __func__, string); + + memset(&data, 0, sizeof(data)); + data.state = (int) state; + + rc = srs_client_send(client, SRS_TEST_SET_RADIO_STATE, &data, sizeof(data)); + if (rc < 0) { + printf("%s: Settings radio state failed\n", __func__); + return -1; + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + int (*callback)(struct srs_client *client, char *string) = NULL; + struct srs_client *client = NULL; + char *string = NULL; + int rc; + + if (argc < 2) { + display_help(); + goto error; + } + + if (strcmp(argv[1], "radio-state") == 0) { + if (argc < 3) { + display_help(); + goto error; + } + + callback = radio_state; + string = argv[2]; + } else { + display_help(); + goto error; + } + + if (callback == NULL) + goto error; + + client = srs_client_create(); + if (client == NULL) { + printf("Creating SRS client failed\n"); + goto error; + } + + rc = srs_client_open(client); + if (rc < 0) { + printf("Opening SRS client failed\n"); + goto error; + } + + rc = callback(client, string); + if (rc < 0) + goto error; + + rc = 0; + goto complete; + +error: + rc = 1; + +complete: + if (client != NULL) { + srs_client_close(client); + srs_client_destroy(client); + } + + return rc; +} -- cgit v1.1