summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-08-16 05:48:59 +0000
committerlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-08-16 05:48:59 +0000
commit1c4526b52edc7c245cb76ba801bbbe9da1a3b5ae (patch)
treec6cc10078666dd145694d72ec497420593b09889 /src/util
parent929473af86307cb76dcb75183094c56c9fce2939 (diff)
Operator Selection (Andrzej Zaborowski)
This adds gsmd/libgsmd/libgmsd-tool commands to: * query available operators, * register to given operator, * register automatically (like gsmd did until now), * deregister, * get current operator name, * query signal quality, * query current connection state (a bit hacky, but it's the only way I found to satisfy the synchronous prototype in misc.h). The operator cache is not used as it wouldn't give any benefit here. Retrieving the list of present operators takes very long but there doesn't seem to exist any way around it and all other phones I used also take that long. The libgmsd call for registration to an automatically chosen operator now takes a parameter of a different type so all libgsmd clients need to be updated (this patch updates libgsmd-tool already, but not libmokogsmd which is not a part of gsmd project). git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@2713 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/util')
-rw-r--r--src/util/shell.c77
1 files changed, 73 insertions, 4 deletions
diff --git a/src/util/shell.c b/src/util/shell.c
index 3f83d30..b2ebfd8 100644
--- a/src/util/shell.c
+++ b/src/util/shell.c
@@ -171,6 +171,54 @@ static int sms_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
}
}
+/* this is the handler for responses to network/operator commands */
+static int net_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
+{
+ const struct gsmd_signal_quality *sq = (struct gsmd_signal_quality *)
+ ((void *) gmh + sizeof(*gmh));
+ const char *oper = (char *) gmh + sizeof(*gmh);
+ const struct gsmd_msg_oper *opers = (struct gsmd_msg_oper *)
+ ((void *) gmh + sizeof(*gmh));
+ static const char *oper_stat[] = {
+ [GSMD_OPER_UNKNOWN] = "of unknown status",
+ [GSMD_OPER_AVAILABLE] = "available",
+ [GSMD_OPER_CURRENT] = "our current operator",
+ [GSMD_OPER_FORBIDDEN] = "forbidden",
+ };
+
+ switch (gmh->msg_subtype) {
+ case GSMD_NETWORK_SIGQ_GET:
+ if (sq->rssi == 99)
+ printf("Signal undetectable\n");
+ else
+ printf("Signal quality %i dBm\n", -113 + sq->rssi * 2);
+ if (sq->ber == 99)
+ printf("Error rate undetectable\n");
+ else
+ printf("Bit error rate %i\n", sq->ber);
+ break;
+ case GSMD_NETWORK_OPER_GET:
+ if (oper[0])
+ printf("Our current operator is %s\n", oper);
+ else
+ printf("No current operator\n");
+ break;
+ case GSMD_NETWORK_OPER_LIST:
+ for (; !opers->is_last; opers ++)
+ printf("%8.*s %16.*s, %.*s for short, is %s\n",
+ sizeof(opers->opname_num),
+ opers->opname_num,
+ sizeof(opers->opname_longalpha),
+ opers->opname_longalpha,
+ sizeof(opers->opname_shortalpha),
+ opers->opname_shortalpha,
+ oper_stat[opers->stat]);
+ break;
+ default:
+ return -EINVAL;
+ }
+}
+
static int shell_help(void)
{
printf( "\tA\tAnswer incoming call\n"
@@ -178,8 +226,12 @@ static int shell_help(void)
"\tH\tHangup call\n"
"\tO\tPower On\n"
"\to\tPower Off\n"
- "\tR\tRegister Network\n"
+ "\tr\tRegister to network\n"
+ "\tR\tRegister to given operator (R=number)\n"
"\tU\tUnregister from netowrk\n"
+ "\tP\tPrint current operator\n"
+ "\tL\tDetect available operators\n"
+ "\tQ\tRead signal quality\n"
"\tT\tSend DTMF Tone\n"
"\tpd\tPB Delete (pb=index)\n"
"\tpr\tPB Read (pr=index)\n"
@@ -208,6 +260,7 @@ int shell_main(struct lgsm_handle *lgsmh)
lgsm_register_handler(lgsmh, GSMD_MSG_PASSTHROUGH, &pt_msghandler);
lgsm_register_handler(lgsmh, GSMD_MSG_PHONEBOOK, &pb_msghandler);
lgsm_register_handler(lgsmh, GSMD_MSG_SMS, &sms_msghandler);
+ lgsm_register_handler(lgsmh, GSMD_MSG_NETWORK, &net_msghandler);
fcntl(0, F_SETFD, O_NONBLOCK);
fcntl(lgsm_fd(lgsmh), F_SETFD, O_NONBLOCK);
@@ -272,12 +325,28 @@ int shell_main(struct lgsm_handle *lgsmh)
} else if (!strcmp(buf, "o")) {
printf("Power-Off\n");
lgsm_phone_power(lgsmh, 0);
- } else if (!strcmp(buf, "R")) {
+ } else if (!strcmp(buf, "r")) {
printf("Register\n");
- lgsm_netreg_register(lgsmh, 0);
+ lgsm_netreg_register(lgsmh, "\0 ");
+ } else if (buf[0] == 'R') {
+ printf("Register to operator\n");
+ ptr = strchr(buf, '=');
+ if (!ptr || strlen(ptr) < 6)
+ printf("No.\n");
+ else
+ lgsm_netreg_register(lgsmh, ptr + 1);
} else if (!strcmp(buf, "U")) {
printf("Unregister\n");
- lgsm_netreg_register(lgsmh, 2);
+ lgsm_netreg_deregister(lgsmh);
+ } else if (!strcmp(buf, "P")) {
+ printf("Read current opername\n");
+ lgsm_oper_get(lgsmh);
+ } else if (!strcmp(buf, "L")) {
+ printf("List operators\n");
+ lgsm_opers_get(lgsmh);
+ } else if (!strcmp(buf, "Q")) {
+ printf("Signal strength\n");
+ lgsm_signal_quality(lgsmh);
} else if (!strcmp(buf, "q")) {
exit(0);
} else if (buf[0] == 'T') {
personal git repositories of Harald Welte. Your mileage may vary