summaryrefslogtreecommitdiff
path: root/src/libgsmd
diff options
context:
space:
mode:
authorlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-04-15 09:47:23 +0000
committerlaforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3>2007-04-15 09:47:23 +0000
commitf243da86ed3c515740870ce0a817f2e768b420fe (patch)
treeb39801affc667465169392855e942e94fb94f4a3 /src/libgsmd
parent6766b42717e386d505ba5f3f7b4732e88eece54e (diff)
* add (still incomplete) SMS and phonebook support from Sean Chiang
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@1765 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/libgsmd')
-rw-r--r--src/libgsmd/Makefile.am2
-rw-r--r--src/libgsmd/libgsmd_phonebook.c146
-rw-r--r--src/libgsmd/libgsmd_sms.c231
3 files changed, 378 insertions, 1 deletions
diff --git a/src/libgsmd/Makefile.am b/src/libgsmd/Makefile.am
index 5ea36f1..20a6725 100644
--- a/src/libgsmd/Makefile.am
+++ b/src/libgsmd/Makefile.am
@@ -5,6 +5,6 @@ AM_CFLAGS = -std=gnu99
lib_LTLIBRARIES = libgsmd.la
libgsmd_la_LDFLAGS = -Wc,-nostartfiles -version-info $(LIBVERSION)
-libgsmd_la_SOURCES = libgsmd.c libgsmd_input.c libgsmd_voicecall.c libgsmd_passthrough.c libgsmd_event.c libgsmd_phone.c libgsmd_network.c libgsmd_pin.c
+libgsmd_la_SOURCES = libgsmd.c libgsmd_input.c libgsmd_voicecall.c libgsmd_passthrough.c libgsmd_event.c libgsmd_phone.c libgsmd_network.c libgsmd_pin.c libgsmd_sms.c libgsmd_phonebook.c
noinst_HEADERS = lgsm_internals.h
diff --git a/src/libgsmd/libgsmd_phonebook.c b/src/libgsmd/libgsmd_phonebook.c
new file mode 100644
index 0000000..c569e02
--- /dev/null
+++ b/src/libgsmd/libgsmd_phonebook.c
@@ -0,0 +1,146 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <libgsmd/libgsmd.h>
+#include <libgsmd/misc.h>
+#include <libgsmd/phonebook.h>
+
+#include <gsmd/usock.h>
+#include <gsmd/event.h>
+
+#include "lgsm_internals.h"
+
+int lgsm_pb_find_entry(struct lgsm_handle *lh,
+ const struct lgsm_phonebook_find *pb_find)
+{
+ struct gsmd_msg_hdr *gmh;
+ struct gsmd_phonebook_find *gpf;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
+ GSMD_PHONEBOOK_FIND, sizeof(*gpf));
+ if (!gmh)
+ return -ENOMEM;
+ gpf = (struct gsmd_phonebook_find *)gmh->data;
+ memcpy(gpf->findtext, pb_find->findtext, sizeof(gpf->findtext));
+ gpf->findtext[sizeof(gpf->findtext)-1] = '\0';
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);;
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsm_pb_read_entry(struct lgsm_handle *lh, int index)
+{
+ struct gsmd_msg_hdr *gmh;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
+ GSMD_PHONEBOOK_READ, sizeof(int));
+ if (!gmh)
+ return -ENOMEM;
+ *(int *) gmh->data = index;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);;
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsm_pb_read_entryies(struct lgsm_handle *lh,
+ const struct lgsm_phonebook_readrg *pb_readrg)
+{
+ struct gsmd_msg_hdr *gmh;
+ struct gsmd_phonebook_readrg *gpr;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
+ GSMD_PHONEBOOK_READRG, sizeof(*gpr));
+ if (!gmh)
+ return -ENOMEM;
+ gpr = (struct gsmd_phonebook_readrg *) gmh->data;
+ gpr->index1 = pb_readrg->index1;
+ gpr->index2 = pb_readrg->index2;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);;
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsmd_pb_del_entry(struct lgsm_handle *lh, int index)
+{
+ struct gsmd_msg_hdr *gmh;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
+ GSMD_PHONEBOOK_DELETE, sizeof(int));
+ if (!gmh)
+ return -ENOMEM;
+
+ *(int *)(gmh->data) = index;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsmd_pb_write_entry(struct lgsm_handle *lh,
+ const struct lgsm_phonebook *pb)
+{
+ /* FIXME: only support alphabet now */
+ struct gsmd_msg_hdr *gmh;
+ struct gsmd_phonebook *gp;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
+ GSMD_PHONEBOOK_WRITE, sizeof(*gp));
+ if (!gmh)
+ return -ENOMEM;
+ gp = (struct gsmd_phonebook *) gmh->data;
+ gp->index = pb->index;
+ memcpy(gp->numb, pb->numb, sizeof(gp->numb));
+ gp->numb[sizeof(gp->numb)-1] = '\0';
+ gp->type = pb->type;
+ memcpy(gp->text, pb->text, sizeof(gp->text));
+ gp->text[sizeof(gp->text)-1] = '\0';
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);;
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+
+int lgsm_pb_get_support(struct lgsm_handle *lh)
+{
+ return lgsm_send_simple(lh, GSMD_MSG_PHONEBOOK, GSMD_PHONEBOOK_GET_SUPPORT);
+}
diff --git a/src/libgsmd/libgsmd_sms.c b/src/libgsmd/libgsmd_sms.c
new file mode 100644
index 0000000..261dca3
--- /dev/null
+++ b/src/libgsmd/libgsmd_sms.c
@@ -0,0 +1,231 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <libgsmd/libgsmd.h>
+#include <libgsmd/misc.h>
+#include <libgsmd/sms.h>
+
+#include <gsmd/usock.h>
+#include <gsmd/event.h>
+
+#include "lgsm_internals.h"
+
+int lgsm_sms_list(struct lgsm_handle *lh, enum gsmd_msg_sms_type stat)
+{
+ /* FIXME: only support PDU mode now */
+ struct gsmd_msg_hdr *gmh;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_SMS,
+ GSMD_SMS_LIST, sizeof(int));
+ if (!gmh)
+ return -ENOMEM;
+ *(int *) gmh->data = stat;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);;
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsm_sms_read(struct lgsm_handle *lh, int index)
+{
+ struct gsmd_msg_hdr *gmh;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_SMS,
+ GSMD_SMS_READ, sizeof(int));
+ if (!gmh)
+ return -ENOMEM;
+ *(int *) gmh->data = index;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);;
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsmd_sms_delete(struct lgsm_handle *lh,
+ const struct lgsm_sms_delete *sms_del)
+{
+ struct gsmd_msg_hdr *gmh;
+ struct gsmd_sms_delete *gsd;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_SMS,
+ GSMD_SMS_DELETE, sizeof(*gsd));
+ if (!gmh)
+ return -ENOMEM;
+ gsd = (struct gsmd_sms_delete *) gmh->data;
+ gsd->index = sms_del->index;
+ gsd->delflg = sms_del->delflg;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsmd_sms_send(struct lgsm_handle *lh,
+ const struct lgsm_sms *sms)
+{
+ /* FIXME: only support PDU mode */
+ struct gsmd_msg_hdr *gmh;
+ struct gsmd_sms *gs;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_SMS,
+ GSMD_SMS_SEND, sizeof(*gs));
+ if (!gmh)
+ return -ENOMEM;
+ gs = (struct gsmd_sms *) gmh->data;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int lgsmd_sms_write(struct lgsm_handle *lh,
+ const struct lgsm_sms_write *sms_write)
+{
+ /* FIXME: only support PDU mode */
+ struct gsmd_msg_hdr *gmh;
+ struct gsmd_sms_write *gsw;
+ int rc;
+
+ gmh = lgsm_gmh_fill(GSMD_MSG_SMS,
+ GSMD_SMS_WRITE, sizeof(*gsw));
+ if (!gmh)
+ return -ENOMEM;
+ gsw = (struct gsmd_sms_write *) gmh->data;
+
+ rc = lgsm_send(lh, gmh);
+ if (rc < gmh->len + sizeof(*gmh)) {
+ lgsm_gmh_free(gmh);
+ return -EIO;
+ }
+
+ lgsm_gmh_free(gmh);
+
+ return 0;
+}
+
+int packing_7bit_character(char *src, char *dest)
+{
+ int i,j = 0;
+ unsigned char ch1, ch2;
+ char tmp[2];
+ int shift = 0;
+
+ *dest = '\0';
+
+ for ( i=0; i<strlen(src); i++ ) {
+
+ ch1 = src[i] & 0x7F;
+ ch1 = ch1 >> shift;
+ ch2 = src[(i+1)] & 0x7F;
+ ch2 = ch2 << (7-shift);
+
+ ch1 = ch1 | ch2;
+
+ j = strlen(dest);
+ sprintf(tmp, "%x", (ch1 >> 4));
+ dest[j++] = tmp[0];
+ sprintf(tmp, "%x", (ch1 & 0x0F));
+ dest[j++] = tmp[0];
+ dest[j++] = '\0';
+
+ shift++;
+
+ if ( 7 == shift ) {
+ shift = 0;
+ i++;
+ }
+ }
+
+ return 0;
+}
+
+int unpacking_7bit_character(char *src, char *dest)
+{
+ unsigned char ch1, ch2 = '\0';
+ int i, j;
+ char buf[8];
+ int shift = 0;
+
+ *dest = '\0';
+
+ for ( i=0; i<strlen(src); i+=2 ) {
+ sprintf(buf, "%c%c", src[i], src[i+1]);
+ ch1 = strtol(buf, NULL, 16);
+
+ j = strlen(dest);
+ dest[j++] = ((ch1 & (0x7F >> shift)) << shift) | ch2;
+ dest[j++] = '\0';
+
+ ch2 = ch1 >> (7-shift);
+
+ shift++;
+ }
+
+ return 0;
+}
+
+/* Refer to 3GPP TS 11.11 Annex B */
+int packing_UCS2_80(char *src, char *dest)
+{
+ return 0;
+}
+
+/* Refer to 3GPP TS 11.11 Annex B */
+int unpacking_UCS2_80(char *src, char *dest)
+{
+ return 0;
+}
+
+/* Refer to 3GPP TS 11.11 Annex B */
+int packing_UCS2_81(char *src, char *dest)
+{
+ return 0;
+}
+
+/* Refer to 3GPP TS 11.11 Annex B */
+int unpacking_UCS2_81(char *src, char *dest)
+{
+ return 0;
+}
+
+/* Refer to 3GPP TS 11.11 Annex B */
+int packing_UCS2_82(char *src, char *dest)
+{
+ return 0;
+}
+
+/* Refer to 3GPP TS 11.11 Annex B */
+int unpacking_UCS2_82(char *src, char *dest)
+{
+ return 0;
+}
personal git repositories of Harald Welte. Your mileage may vary