aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorPaulK <contact@paulk.fr>2011-10-31 14:55:18 +0100
committerPaulK <contact@paulk.fr>2011-10-31 14:55:18 +0100
commitf96de31528f35486d79a7741495e1b383fc236ec (patch)
tree6f96e1aef408d88af0a48c7c364a1a18378cfa05 /tools
parentc9210b62c93a8f9a8bba249dfffc86762bc69234 (diff)
downloadexternal_libsamsung-ipc-f96de31528f35486d79a7741495e1b383fc236ec.zip
external_libsamsung-ipc-f96de31528f35486d79a7741495e1b383fc236ec.tar.gz
external_libsamsung-ipc-f96de31528f35486d79a7741495e1b383fc236ec.tar.bz2
Implemented minimal ipc upper-layer in modemctrl, with auto call functions
Diffstat (limited to 'tools')
-rw-r--r--tools/modemctrl.c340
1 files changed, 300 insertions, 40 deletions
diff --git a/tools/modemctrl.c b/tools/modemctrl.c
index ff56c48..a80400a 100644
--- a/tools/modemctrl.c
+++ b/tools/modemctrl.c
@@ -35,26 +35,284 @@
#define RC_CHECK printf("line %d, rc = %d\n", __LINE__, rc);
+#define MODEM_STATE_LPM 0
+#define MODEM_STATE_NORMAL 2
+#define MODEM_STATE_SIM_OK 4
+
+#define DEF_CALL_NUMBER "950"
+#define DEF_SIM_PIN "1234"
+
+int client_fd = -1;
+int state = MODEM_STATE_LPM;
+int seq = 0;
+int in_call = 0;
+int call_done = 0;
+
+int seq_get(void)
+{
+ if(seq == 0xff)
+ seq = 0x00;
+
+ seq++;
+
+ return seq;
+}
+
void print_help()
{
printf("usage: modemctrl <command>\n");
printf("commands:\n");
- printf("\tbootstrap bootstrap modem to be ready for processing\n");
+ printf("\tstart-fmt bootstrap modem and start read loop\n");
printf("\tpower-on power on the modem\n");
printf("\tpower-off power off the modem\n");
}
-int crespo_read_loop(struct ipc_client *client)
+void modem_exec_call_out(struct ipc_client *client, char *num)
+{
+ struct ipc_call_outgoing out_call;
+
+ memset(&out_call, 0, sizeof(struct ipc_call_outgoing));
+
+ out_call.type = IPC_CALL_TYPE_VOICE;
+ out_call.identity = IPC_CALL_IDENTITY_DEFAULT;
+ out_call.length=strlen(num);
+ out_call.prefix=0x21;//IPC_CALL_PREFIX_NONE;
+ memcpy(out_call.number, num, out_call.length);
+
+ ipc_client_send(client, IPC_CALL_OUTGOING, IPC_TYPE_EXEC, &out_call, sizeof(struct ipc_call_outgoing), seq_get());
+}
+
+void modem_exec_call_answer(struct ipc_client *client)
+{
+// ipc_request_snd_clock_ctrl(client);
+ ipc_client_send(client, IPC_CALL_ANSWER, IPC_TYPE_EXEC, NULL, 0, seq_get());
+
+/*
+ ipc_request_no_mic_mute(client);
+ ipc_request_snd_spkr_volume_ctrl(client);
+ ipc_request_snd_audio_path_ctrl(client);
+*/
+}
+
+void modem_get_call_list(struct ipc_client *client)
+{
+ ipc_client_send(client, IPC_CALL_LIST, IPC_TYPE_GET, NULL, 0, seq_get());
+
+ //ipc_request_no_mic_mute(client);
+}
+
+void modem_exec_power_normal(struct ipc_client *client)
+{
+ printf("%s()\n", __FUNCTION__);
+ uint16_t data;
+
+ data = 0x0202;
+
+ ipc_client_send(client, IPC_PWR_PHONE_STATE, IPC_TYPE_EXEC, (char *)&data, sizeof(data), seq_get());
+}
+
+void modem_set_sms_device_ready(struct ipc_client *client)
+{
+ printf("%s()\n", __FUNCTION__);
+ ipc_client_send(client, IPC_SMS_DEVICE_READY, IPC_TYPE_SET, NULL, 0, seq_get());
+
+}
+
+void modem_set_sec_pin_status(struct ipc_client *client, char *pin1, char *pin2)
+{
+ printf("%s()\n", __FUNCTION__);
+ struct ipc_sec_pin_status_set pin_status;
+ struct ipc_sec_lock_info_request lock_info_req;
+
+ printf("Sending PIN1 unlock request\n");
+
+ ipc_sec_pin_status_set_setup(&pin_status, IPC_SEC_PIN_TYPE_PIN1, pin1, pin2);
+ ipc_client_send(client, IPC_SEC_PIN_STATUS, IPC_TYPE_SET, &pin_status, sizeof(pin_status), seq_get());
+}
+
+void modem_response_sec(struct ipc_client *client, struct ipc_message_info *resp)
+{
+ struct ipc_sec_pin_status_noti *pin_status;
+ unsigned char type;
+ int status;
+ char *data;
+
+ switch(IPC_COMMAND(resp))
+ {
+ case IPC_SEC_PIN_STATUS :
+ pin_status = (struct ipc_sec_pin_status_noti *)resp->data;
+
+ switch(pin_status->type)
+ {
+ case IPC_SEC_PIN_SIM_INITIALIZING:
+ printf("SIM is initializing\n");
+ break;
+ case IPC_SEC_PIN_SIM_CARD_NOT_PRESENT:
+ printf("SIM card is definitely absent\n");
+ break;
+ case IPC_SEC_PIN_SIM_LOCK_SC:
+ switch(pin_status->key)
+ {
+ case IPC_SEC_PIN_SIM_LOCK_SC_PIN1_REQ:
+ printf("We need the PIN1 to unlock the card!\n");
+ modem_set_sec_pin_status(client, DEF_SIM_PIN, NULL);
+ break;
+ case IPC_SEC_PIN_SIM_LOCK_SC_PUK_REQ:
+ printf("Please provide the SIM card PUK!\n");
+ break;
+ case IPC_SEC_PIN_SIM_LOCK_SC_CARD_BLOCKED:
+ printf("Ouch, the SIM Card is blocked.\n");
+ break;
+ }
+ break;
+ case IPC_SEC_PIN_SIM_INIT_COMPLETE:
+ printf("SIM init complete\n");
+ if(state == MODEM_STATE_NORMAL)
+ state = MODEM_STATE_SIM_OK;
+
+ break;
+ case IPC_SEC_PIN_SIM_PB_INIT_COMPLETE:
+ printf("SIM Phone Book init complete\n");
+ break;
+ }
+ break;
+ case IPC_SEC_SIM_ICC_TYPE:
+ type = *((char *) resp->data);
+ switch(type)
+ {
+ case IPC_SEC_SIM_CARD_TYPE_UNKNOWN:
+ printf("No SIM card type is unknown (absent?)\n");
+ break;
+ case IPC_SEC_SIM_CARD_TYPE_SIM:
+ case IPC_SEC_SIM_CARD_TYPE_USIM:
+ printf("SIM card found\n");
+ break;
+ }
+ break;
+ }
+}
+
+void modem_response_sms(struct ipc_client *client, struct ipc_message_info *resp)
+{
+ switch(IPC_COMMAND(resp))
+ {
+ case IPC_SMS_DEVICE_READY:
+ printf("SMS device ready!\n");
+
+ if(state == MODEM_STATE_LPM)
+ modem_exec_power_normal(client);
+ else if(state == MODEM_STATE_SIM_OK)
+ modem_set_sms_device_ready(client);
+ break;
+ }
+}
+
+void modem_response_call(struct ipc_client *client, struct ipc_message_info *resp)
+{
+ switch(IPC_COMMAND(resp))
+ {
+ case IPC_CALL_LIST:
+ if(in_call)
+ modem_exec_call_answer(client);
+ break;
+ case IPC_CALL_INCOMING:
+ printf("Got an incoming call!\n");
+ in_call = 1;
+ modem_get_call_list(client);
+ break;
+ case IPC_CALL_STATUS:
+
+ break;
+ }
+}
+
+void modem_response_pwr(struct ipc_client *client, struct ipc_message_info *resp)
+{
+ int state_n;
+
+ switch(IPC_COMMAND(resp))
+ {
+ case IPC_PWR_PHONE_PWR_UP:
+ printf("Phone PWR UP!\n");
+ state = MODEM_STATE_LPM;
+ break;
+ case IPC_PWR_PHONE_STATE:
+ state_n = *((int *)resp->data);
+
+ switch(state_n)
+ {
+ /* FIXME: Broken */
+ case IPC_PWR_PHONE_STATE_NORMAL:
+ printf("Power state is now: NORMAL\n");
+ break;
+ case IPC_PWR_PHONE_STATE_LPM:
+ printf("Power state is now: LPM (Low Power Mode)?\n");
+ break;
+ }
+
+ state = state_n;
+ break;
+ }
+}
+
+void modem_response_net(struct ipc_client *client, struct ipc_message_info *resp)
+{
+ struct ipc_net_regist *regi;
+
+ switch(IPC_COMMAND(resp))
+ {
+ case IPC_NET_REGIST:
+ regi = (struct ipc_net_regist *)resp->data;
+ if(regi->reg_state == IPC_NET_REGISTRATION_STATE_HOME)
+ {
+ printf("Registered with network successfully!\n");
+
+ }
+ break;
+ case IPC_NET_CURRENT_PLMN:
+ if(call_done == 0)
+ {
+ printf("Requesting outgoing call to %s!\n", DEF_CALL_NUMBER);
+ modem_exec_call_out(client, DEF_CALL_NUMBER);
+ }
+ call_done = 1;
+ break;
+ }
+}
+
+void modem_response_handle(struct ipc_client *client, struct ipc_message_info *resp)
+{
+ switch(resp->group)
+ {
+ case IPC_GROUP_NET:
+ modem_response_net(client, resp);
+ break;
+ case IPC_GROUP_PWR:
+ modem_response_pwr(client, resp);
+ break;
+ case IPC_GROUP_SEC:
+ modem_response_sec(client, resp);
+ break;
+ case IPC_GROUP_SMS:
+ modem_response_sms(client, resp);
+ break;
+ case IPC_GROUP_CALL:
+ modem_response_call(client, resp);
+ break;
+ case IPC_GROUP_DISP:
+ // if(in_call)
+ // modem_request_no_mic_mute(client);
+ break;
+ }
+}
+
+int modem_read_loop(struct ipc_client *client)
{
-#if 0
struct ipc_message_info resp;
- void *io_data = NULL;
- int fd = -1;
+ int fd = client_fd;
+ int rc;
fd_set fds;
- io_data = ipc_client_get_handlers_io_data(client);
- fd = *((int *) io_data);
-
if(fd < 0) {
return -1;
}
@@ -71,46 +329,55 @@ int crespo_read_loop(struct ipc_client *client)
if(FD_ISSET(fd, &fds))
{
- ipc_client_recv(client, &resp);
+ rc = ipc_client_recv(client, &resp);
+
+ if(rc < 0)
+ break;
+
+ modem_response_handle(client, &resp);
+
if(resp.data != NULL)
free(resp.data);
}
}
-#endif
+
return 0;
}
int modem_start(struct ipc_client *client)
{
- int rc;
+ int rc = -1;
+
+// ipc_client_set_handlers(client, &ipc_default_handlers);
+
+ ipc_client_set_all_handlers_data(client, &client_fd);
- // ipc_client_set_handlers(client, &ipc_default_handlers);
ipc_client_bootstrap_modem(client);
- rc = ipc_client_power_on(client);
- if(rc < 0)
- return -1;
+ usleep(300);
rc = ipc_client_open(client);
if(rc < 0)
return -1;
+ rc = ipc_client_power_on(client);
+ if(rc < 0)
+ return -1;
return 0;
}
int modem_stop(struct ipc_client *client)
{
- ipc_client_close(client);
ipc_client_power_off(client);
+ ipc_client_close(client);
return 0;
}
int main(int argc, char *argv[])
{
- struct ipc_client *crespo_fmt_client;
- struct ipc_client *crespo_rfs_client;
+ struct ipc_client *client_fmt;
int rc;
if (argc != 2) {
@@ -118,43 +385,36 @@ int main(int argc, char *argv[])
exit(1);
}
- crespo_fmt_client = ipc_client_new(IPC_CLIENT_TYPE_FMT);
- crespo_rfs_client = ipc_client_new(IPC_CLIENT_TYPE_RFS);
+ client_fmt = ipc_client_new(IPC_CLIENT_TYPE_FMT);
if (!strncmp(argv[1], "power-on", sizeof("power-on"))) {
- ipc_client_power_on(crespo_fmt_client);
+ ipc_client_power_on(client_fmt);
}
else if (!strncmp(argv[1], "power-off", sizeof("power-off"))) {
- ipc_client_power_off(crespo_fmt_client);
- }
-
- else if (!strncmp(argv[1], "stop-all", 8)) {
- ipc_client_close(crespo_fmt_client);
- ipc_client_close(crespo_rfs_client);
- ipc_client_power_off(crespo_fmt_client);
+ ipc_client_power_off(client_fmt);
}
else if (!strncmp(argv[1], "start-fmt", 9)) {
printf("Starting modem on FMT client\n");
- rc = modem_start(crespo_fmt_client);
+ rc = modem_start(client_fmt);
if(rc < 0) {
- printf("Somethign went wrong\n");
- modem_stop(crespo_fmt_client);
+ printf("Something went wrong\n");
+ modem_stop(client_fmt);
return 1;
}
- printf("Starting crespo_read_loop on FMT client\n");
- crespo_read_loop(crespo_fmt_client);
+ printf("Starting modem_read_loop on FMT client\n");
+ modem_read_loop(client_fmt);
- modem_stop(crespo_fmt_client);
+ modem_stop(client_fmt);
}
-
+/*
else if (!strncmp(argv[1], "start-rfs", 9)) {
printf("Starting modem on RFS client\n");
- rc = modem_start(crespo_rfs_client);
- if(rc < 0) {
- printf("Somethign went wrong\n");
+ fd = modem_start(crespo_rfs_client);
+ if(fd < 0) {
+ printf("Something went wrong\n");
modem_stop(crespo_rfs_client);
return 1;
}
@@ -164,12 +424,12 @@ int main(int argc, char *argv[])
modem_stop(crespo_rfs_client);
}
+*/
else {
printf("Unknown command!\n");
}
- ipc_client_free(crespo_fmt_client);
- ipc_client_free(crespo_rfs_client);
+ ipc_client_free(client_fmt);
return 0;
}