[PATCH 02/13] Add parser for url objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 3fac701..2fc5287 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1014,6 +1014,14 @@ static gboolean parse_dataobj_browser_id(struct 
comprehension_tlv_iter *iter,
return parse_dataobj_common_byte(iter, byte);
 }
 
+/* Defined in TS 102.223 Section 8.48 */
+static gboolean parse_dataobj_url(struct comprehension_tlv_iter *iter,
+   void *user)
+{
+   char **url = user;
+   return parse_dataobj_common_text(iter, url);
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1138,6 +1146,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_language;
case STK_DATA_OBJECT_TYPE_BROWSER_ID:
return parse_dataobj_browser_id;
+   case STK_DATA_OBJECT_TYPE_URL:
+   return parse_dataobj_url;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 05/13] Add parser for provisioning file reference objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   28 
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 8b53e6d..2b551e2 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1058,6 +1058,32 @@ static gboolean parse_dataobj_bearer(struct 
comprehension_tlv_iter *iter,
return parse_dataobj_common_byte_array(iter, array);
 }
 
+/* Defined in TS 102.223 Section 8.50 */
+static gboolean parse_dataobj_provisioning_file_reference(
+   struct comprehension_tlv_iter *iter, void *user)
+{
+   struct stk_file *f = user;
+   const unsigned char *data;
+   struct stk_file_iter sf_iter;
+   unsigned int len = comprehension_tlv_iter_get_length(iter);
+
+   if ((len  1) || (len  8))
+   return FALSE;
+
+   data = comprehension_tlv_iter_get_data(iter);
+
+   stk_file_iter_init(sf_iter, data, len);
+   stk_file_iter_next(sf_iter);
+
+   if (sf_iter.pos != sf_iter.max)
+   return FALSE;
+
+   f-len = len;
+   memcpy(f-file, data, len);
+
+   return TRUE;
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1186,6 +1212,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_url;
case STK_DATA_OBJECT_TYPE_BEARER:
return parse_dataobj_bearer;
+   case STK_DATA_OBJECT_TYPE_PROVISIONING_FILE_REFERENCE:
+   return parse_dataobj_provisioning_file_reference;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 03/13] Add parser for bearer objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   10 ++
 src/stkutil.h |7 +++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 2fc5287..c249a3a 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1022,6 +1022,14 @@ static gboolean parse_dataobj_url(struct 
comprehension_tlv_iter *iter,
return parse_dataobj_common_text(iter, url);
 }
 
+/* Defined in TS 102.223 Section 8.49 */
+static gboolean parse_dataobj_bearer(struct comprehension_tlv_iter *iter,
+   void *user)
+{
+   struct stk_common_byte_array *array = user;
+   return parse_dataobj_common_byte_array(iter, array);
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1148,6 +1156,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_browser_id;
case STK_DATA_OBJECT_TYPE_URL:
return parse_dataobj_url;
+   case STK_DATA_OBJECT_TYPE_BEARER:
+   return parse_dataobj_bearer;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
diff --git a/src/stkutil.h b/src/stkutil.h
index 3f96159..3dcb2c3 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -309,6 +309,13 @@ enum stk_browser_id {
STK_BROWSER_ID_CHTML =  0x04
 };
 
+enum stk_bearer {
+   STK_BEARER_SMS =0x00,
+   STK_BEARER_CS_DATA =0x01,
+   STK_BEARER_GSM_3G = 0x02,
+   STK_BEARER_PS = 0x03
+};
+
 /* For data object that only has a byte array with undetermined length */
 struct stk_common_byte_array {
unsigned char *array;
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 07/13] Add parser for bearer description objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   21 +
 src/stkutil.h |   23 +++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 4998440..f27ff69 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1092,6 +1092,25 @@ static gboolean parse_dataobj_browser_termination_cause(
return parse_dataobj_common_byte(iter, byte);
 }
 
+/* Defined in TS 102.223 Section 8.52 */
+static gboolean parse_dataobj_bearer_description(
+   struct comprehension_tlv_iter *iter, void *user)
+{
+   struct stk_bearer_description *bd = user;
+   const unsigned char *data;
+   unsigned int len = comprehension_tlv_iter_get_length(iter);
+
+   if (len  1)
+   return FALSE;
+
+   data = comprehension_tlv_iter_get_data(iter);
+   bd-type = data[0];
+   bd-len = len - 1;
+   memcpy(bd-pars, data + 1, bd-len);
+
+   return TRUE;
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1224,6 +1243,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_provisioning_file_reference;
case STK_DATA_OBJECT_TYPE_BROWSER_TERMINATION_CAUSE:
return parse_dataobj_browser_termination_cause;
+   case STK_DATA_OBJECT_TYPE_BEARER_DESCRIPTION:
+   return parse_dataobj_bearer_description;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
diff --git a/src/stkutil.h b/src/stkutil.h
index 746c5ff..c1b9af0 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -321,6 +321,17 @@ enum stk_browser_termination_cause {
STK_BROWSER_ERROR_TERMINATION = 0x01
 };
 
+enum stk_bearer_type {
+   STK_BEARER_TYPE_DEFAULT =   0x03,
+   STK_BEARER_TYPE_INDEPENDENT =   0x04,
+   STK_BEARER_TYPE_BLUETOOTH = 0x05,
+   STK_BEARER_TYPE_IRDA =  0x06,
+   STK_BEARER_TYPE_RS232 = 0x07,
+   STK_BEARER_TYPE_PACKET_DATA_SERVICE =   0x08,
+   STK_BEARER_TYPE_I_WLAN =0x0a,
+   STK_BEARER_TYPE_USB =   0x10
+};
+
 /* For data object that only has a byte array with undetermined length */
 struct stk_common_byte_array {
unsigned char *array;
@@ -521,6 +532,18 @@ struct stk_timer_value {
 };
 
 /*
+ * According to 102.223 Section 8.52 the length of CTLV is 1 byte. This means
+ * that the maximum size is 127 according to the rules of CTLVs. This size also
+ * includes bearer type for 1 byte, so the maxmimum size of bearer parameters
+ * is 126.
+ */
+struct stk_bearer_description {
+   unsigned char type;
+   unsigned char pars[126];
+   unsigned int len;
+};
+
+/*
  * According to 102.223 Section 8.72 the length of text attribute CTLV is 1
  * byte.  This means that the maximum size is 127 according to the rules
  * of CTLVs.  Empty attribute options will have len of 0.
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 01/13] Fix the logic when parsing c-apdu objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 13c2978..3fac701 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -852,7 +852,6 @@ static gboolean parse_dataobj_c_apdu(struct 
comprehension_tlv_iter *iter,
}

if (len - pos  0) {
-   ca-lc = 0;
ca-le = data[len - 1];
ca-has_le = TRUE;
}
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 04/13] Break out stk_file iterator to parse file list objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |  166 +
 1 files changed, 97 insertions(+), 69 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index c249a3a..8b53e6d 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -39,6 +39,14 @@ enum stk_data_object_flag {
DATAOBJ_FLAG_MINIMUM = 2
 };
 
+struct stk_file_iter {
+   const unsigned char *start;
+   unsigned int pos;
+   unsigned int max;
+   unsigned char len;
+   const unsigned char *file;
+};
+
 typedef gboolean (*dataobj_handler)(struct comprehension_tlv_iter *, void *);
 
 /*
@@ -157,6 +165,86 @@ static gboolean parse_dataobj_common_byte_array(
return TRUE;
 }
 
+static void stk_file_iter_init(struct stk_file_iter *iter,
+   const unsigned char *start, unsigned int len)
+{
+   iter-start = start;
+   iter-max = len;
+   iter-pos = 0;
+}
+
+static gboolean stk_file_iter_next(struct stk_file_iter *iter)
+{
+   unsigned int pos = iter-pos;
+   const unsigned int max = iter-max;
+   const unsigned char *start = iter-start;
+   unsigned int i;
+   unsigned char last_type;
+
+   /* SIM EFs always start with ROOT MF, 0x3f */
+   if (start[iter-pos] != 0x3f)
+   return FALSE;
+
+   if (pos + 2 = max)
+   return FALSE;
+
+   last_type = 0x3f;
+
+   for (i = pos + 2; i  max; i += 2) {
+   /*
+* Check the validity of file type.
+* According to TS 11.11, each file id contains of two bytes,
+* in which the first byte is the type of file. For GSM is:
+* 0x3f: master file
+* 0x7f: 1st level dedicated file
+* 0x5f: 2nd level dedicated file
+* 0x2f: elementary file under the master file
+* 0x6f: elementary file under 1st level dedicated file
+* 0x4f: elementary file under 2nd level dedicated file
+*/
+   switch (start[i]) {
+   case 0x2f:
+   if (last_type != 0x3f)
+   return FALSE;
+   break;
+   case 0x6f:
+   if (last_type != 0x7f)
+   return FALSE;
+   break;
+   case 0x4f:
+   if (last_type != 0x5f)
+   return FALSE;
+   break;
+   case 0x7f:
+   if (last_type != 0x3f)
+   return FALSE;
+   break;
+   case 0x5f:
+   if (last_type != 0x7f)
+   return FALSE;
+   break;
+   default:
+   return FALSE;
+   }
+
+   if ((start[i] == 0x2f) || (start[i] == 0x6f) ||
+   (start[i] == 0x4f)) {
+   if (i + 1 = max)
+   return FALSE;
+
+   iter-file = start + pos;
+   iter-len = i - pos + 2;
+   iter-pos = i + 2;
+
+   return TRUE;
+   }
+
+   last_type = start[i];
+   }
+
+   return FALSE;
+}
+
 /* Defined in TS 102.223 Section 8.1 */
 static gboolean parse_dataobj_address(struct comprehension_tlv_iter *iter,
void *user)
@@ -443,10 +531,8 @@ static gboolean parse_dataobj_file_list(struct 
comprehension_tlv_iter *iter,
GSList **fl = user;
const unsigned char *data;
unsigned int len;
-   unsigned int i;
-   unsigned int start;
struct stk_file *sf;
-   unsigned char last_type;
+   struct stk_file_iter sf_iter;
 
len = comprehension_tlv_iter_get_length(iter);
if (len  5)
@@ -454,77 +540,19 @@ static gboolean parse_dataobj_file_list(struct 
comprehension_tlv_iter *iter,
 
data = comprehension_tlv_iter_get_data(iter);
 
-   /* SIM EFs always start with ROOT MF, 0x3f */
-   if (data[1] != 0x3f)
-   return FALSE;
-
-   start = 1;
-   last_type = 0x3f;
-
-   for (i = 3; i  len; i += 2) {
-   /*
-* Check the validity of file type.
-* According to TS 11.11, each file id contains of two bytes,
-* in which the first byte is the type of file. For GSM is:
-* 0x3f: master file
-* 0x7f: 1st level dedicated file
-* 0x5f: 2nd level dedicated file
-* 0x2f: elementary file under the master file
-* 0x6f: elementary file under 1st level dedicated file
-* 0x4f: elementary file under 2nd level dedicated file
-*/
-   switch (data[i]) {
-   case 0x3f:
-

[PATCH 11/13] Add parser for channel status objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   20 
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 30c476d..01124a5 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1143,6 +1143,24 @@ static gboolean parse_dataobj_buffer_size(struct 
comprehension_tlv_iter *iter,
return TRUE;
 }
 
+/* Defined in TS 102.223 Section 8.56 */
+static gboolean parse_dataobj_channel_status(
+   struct comprehension_tlv_iter *iter, void *user)
+{
+   unsigned char *status = user;
+   const unsigned char *data;
+
+   if (comprehension_tlv_iter_get_length(iter) != 2)
+   return FALSE;
+
+   data = comprehension_tlv_iter_get_data(iter);
+
+   /* Assume channel status is 2 bytes long */
+   memcpy(status, data, 2);
+
+   return TRUE;
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1283,6 +1301,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_channel_data_length;
case STK_DATA_OBJECT_TYPE_BUFFER_SIZE:
return parse_dataobj_buffer_size;
+   case STK_DATA_OBJECT_TYPE_CHANNEL_STATUS:
+   return parse_dataobj_channel_status;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 12/13] Add parser for card reader identifier objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   20 
 src/stkutil.h |9 +
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 01124a5..28a09d9 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1161,6 +1161,24 @@ static gboolean parse_dataobj_channel_status(
return TRUE;
 }
 
+/* Defined in TS 102.223 Section 8.57 */
+static gboolean parse_dataobj_card_reader_id(
+   struct comprehension_tlv_iter *iter, void *user)
+{
+   struct stk_card_reader_id *cr_id = user;
+   const unsigned char *data;
+   unsigned int len = comprehension_tlv_iter_get_length(iter);
+
+   if (len  1)
+   return FALSE;
+
+   data = comprehension_tlv_iter_get_data(iter);
+   cr_id-len = len;
+   memcpy(cr_id-id, data, len);
+
+   return TRUE;
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1303,6 +1321,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_buffer_size;
case STK_DATA_OBJECT_TYPE_CHANNEL_STATUS:
return parse_dataobj_channel_status;
+   case STK_DATA_OBJECT_TYPE_CARD_READER_ID:
+   return parse_dataobj_card_reader_id;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
diff --git a/src/stkutil.h b/src/stkutil.h
index c1b9af0..511b912 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -544,6 +544,15 @@ struct stk_bearer_description {
 };
 
 /*
+ * According to 102.223 Section 8.57 the length of CTLV is 1 byte. This means
+ * that the maximum size is 127 according to the rules of CTLVs.
+ */
+struct stk_card_reader_id {
+   unsigned char id[127];
+   unsigned char len;
+};
+
+/*
  * According to 102.223 Section 8.72 the length of text attribute CTLV is 1
  * byte.  This means that the maximum size is 127 according to the rules
  * of CTLVs.  Empty attribute options will have len of 0.
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 09/13] Add parser for channel data length objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 0c9108f..b841fa6 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1119,6 +1119,14 @@ static gboolean parse_dataobj_channel_data(struct 
comprehension_tlv_iter *iter,
return parse_dataobj_common_byte_array(iter, array);
 }
 
+/* Defined in TS 102.223 Section 8.54 */
+static gboolean parse_dataobj_channel_data_length(
+   struct comprehension_tlv_iter *iter, void *user)
+{
+   unsigned char *byte = user;
+   return parse_dataobj_common_byte(iter, byte);
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1255,6 +1263,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_bearer_description;
case STK_DATA_OBJECT_TYPE_CHANNEL_DATA:
return parse_dataobj_channel_data;
+   case STK_DATA_OBJECT_TYPE_CHANNEL_DATA_LENGTH:
+   return parse_dataobj_channel_data_length;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 13/13] Add parser for other address objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   23 +++
 src/stkutil.h |   14 ++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 28a09d9..7d9e2e0 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1179,6 +1179,27 @@ static gboolean parse_dataobj_card_reader_id(
return TRUE;
 }
 
+/* Defined in TS 102.223 Section 8.58 */
+static gboolean parse_dataobj_other_address(
+   struct comprehension_tlv_iter *iter, void *user)
+{
+   struct stk_other_address *oa = user;
+   const unsigned char *data;
+   unsigned char len = comprehension_tlv_iter_get_length(iter);
+
+   if (len == 0)
+   return TRUE;
+
+   if ((len != 5)  (len != 17))
+   return FALSE;
+
+   data = comprehension_tlv_iter_get_data(iter);
+   oa-type = data[0];
+   memcpy(oa-addr, data + 1, len - 1);
+
+   return TRUE;
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1323,6 +1344,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_channel_status;
case STK_DATA_OBJECT_TYPE_CARD_READER_ID:
return parse_dataobj_card_reader_id;
+   case STK_DATA_OBJECT_TYPE_OTHER_ADDRESS:
+   return parse_dataobj_other_address;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
diff --git a/src/stkutil.h b/src/stkutil.h
index 511b912..0811048 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -332,6 +332,11 @@ enum stk_bearer_type {
STK_BEARER_TYPE_USB =   0x10
 };
 
+enum stk_address_type {
+   STK_ADDRESS_IPV4 =  0x21,
+   STK_ADDRESS_IPV6 =  0x57
+};
+
 /* For data object that only has a byte array with undetermined length */
 struct stk_common_byte_array {
unsigned char *array;
@@ -553,6 +558,15 @@ struct stk_card_reader_id {
 };
 
 /*
+ * According to 102.223 Section 8.58 the address can be either ipv4 or ipv6.
+ * So the maximum size is 16 (for ipv6).
+ */
+struct stk_other_address {
+   unsigned char addr[16];
+   unsigned char type;
+};
+
+/*
  * According to 102.223 Section 8.72 the length of text attribute CTLV is 1
  * byte.  This means that the maximum size is 127 according to the rules
  * of CTLVs.  Empty attribute options will have len of 0.
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 06/13] Add parser for browser termination cause objects

2010-04-06 Thread Yang Gu
---
 src/stkutil.c |   10 ++
 src/stkutil.h |5 +
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 2b551e2..4998440 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -1084,6 +1084,14 @@ static gboolean 
parse_dataobj_provisioning_file_reference(
return TRUE;
 }
 
+/* Defined in 102.223 Section 8.51 */
+static gboolean parse_dataobj_browser_termination_cause(
+   struct comprehension_tlv_iter *iter, void *user)
+{
+   unsigned char *byte = user;
+   return parse_dataobj_common_byte(iter, byte);
+}
+
 /* Defined in TS 102.223 Section 8.72 */
 static gboolean parse_dataobj_text_attr(struct comprehension_tlv_iter *iter,
void *user)
@@ -1214,6 +1222,8 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
return parse_dataobj_bearer;
case STK_DATA_OBJECT_TYPE_PROVISIONING_FILE_REFERENCE:
return parse_dataobj_provisioning_file_reference;
+   case STK_DATA_OBJECT_TYPE_BROWSER_TERMINATION_CAUSE:
+   return parse_dataobj_browser_termination_cause;
case STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE:
return parse_dataobj_text_attr;
case STK_DATA_OBJECT_TYPE_FRAME_ID:
diff --git a/src/stkutil.h b/src/stkutil.h
index 3dcb2c3..746c5ff 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -316,6 +316,11 @@ enum stk_bearer {
STK_BEARER_PS = 0x03
 };
 
+enum stk_browser_termination_cause {
+   STK_BROWSER_USER_TERMINATION =  0x00,
+   STK_BROWSER_ERROR_TERMINATION = 0x01
+};
+
 /* For data object that only has a byte array with undetermined length */
 struct stk_common_byte_array {
unsigned char *array;
-- 
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 1/2] Added rules to disable SQLite history plugin

2010-04-06 Thread Dario

---
Makefile.am  |   10 ++
configure.ac |9 +
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index ee10095..adff96f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -222,6 +222,16 @@ builtin_modules += example_history
builtin_sources += plugins/example_history.c
endif

+if SQLITEHISTORY
+builtin_modules += sqlite_history
+builtin_sources += plugins/sqlite_history.c
+builtin_cflags += @SQLITE3_CFLAGS@
+builtin_libadd += @SQLITE3_LIBS@
+
+sqlitescriptsdir = $(localstatedir)/lib/ofono
+sqlitescripts_DATA = plugins/*.sql
+endif
+
sbin_PROGRAMS = src/ofonod

src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) \
diff --git a/configure.ac b/configure.ac
index d2f921f..997ee9f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -151,6 +151,15 @@ AC_ARG_ENABLE(datafiles, 
AC_HELP_STRING([--disable-datafiles],


AM_CONDITIONAL(DATAFILES, test ${enable_datafiles} != no)

+AC_ARG_ENABLE(sqlitehistory, AC_HELP_STRING([--disable-sqlitehistory],
+[don't install sqlite history plugin]),
+[enable_sqlitehistory=${enableval}])
+
+AM_CONDITIONAL(SQLITEHISTORY, test ${enable_sqlitehistory} != no)
+if (test ${enable_sqlitehistory} != no); then
+PKG_CHECK_MODULES(SQLITE3, sqlite3)
+fi
+
if (test ${prefix} = NONE); then
dnl no prefix and no localstatedir, so default to /var
if (test $localstatedir = '${prefix}/var'); then
--
1.6.3.3

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH 2/2] Added SQLite history plugin

2010-04-06 Thread Dario

---
plugins/oFono_History_DB.sql |   27 
plugins/sqlite_history.c |  301 ++
2 files changed, 328 insertions(+), 0 deletions(-)
create mode 100644 plugins/oFono_History_DB.sql
create mode 100644 plugins/sqlite_history.c

diff --git a/plugins/oFono_History_DB.sql b/plugins/oFono_History_DB.sql
new file mode 100644
index 000..7cfc3ba
--- /dev/null
+++ b/plugins/oFono_History_DB.sql
@@ -0,0 +1,27 @@
+CREATE TABLE IF NOT EXISTS ofono_history_calls (
+ohc_modem_path TEXT, -- Modem path string i.e. /modem0
+ohc_type INTEGER, -- Call type ( 0 = Call ended, 1 = Call missed )
+ohc_direction INTEGER, -- Call direction ( 0 = Mobile Originated, 1 = 
Mobile Terminated )
+ohc_phone_number TEXT, -- Other party phone number
+ohc_start_time TEXT, -- Starting date/time
+ohc_end_time TEXT -- Ending date/time
+);
+CREATE TABLE IF NOT EXISTS ofono_history_incoming_messages (
+ohim_modem_path TEXT, -- Modem path string i.e. /modem0
+ohim_msg_id INTEGER, -- oFono unique message id number
+ohim_sender TEXT, -- Sender phone number
+ohim_text TEXT, -- Message text
+ohim_local_date TEXT, -- Local sent date/time
+ohim_remote_date TEXT -- Remote sent date/time
+);
+CREATE TABLE IF NOT EXISTS ofono_history_outgoing_messages (
+ohom_modem_path TEXT, -- Modem path string i.e. /modem0
+ohom_msg_id INTEGER, -- oFono unique message id number
+ohom_recipient TEXT, -- Recipient phone number
+ohom_text TEXT, -- Message text
+ohom_creation_date TEXT, -- Message creation date/time
+ohom_send_status INTEGER, -- Sending status ( 0 = Pending, 1 = 
Submitted, 2 = Failed )
+ohom_status_update_date TEXT -- Last row update date/time
+);
+CREATE UNIQUE INDEX IF NOT EXISTS ohim_idx_msg_id on 
ofono_history_incoming_messages (ohim_msg_id ASC);
+CREATE UNIQUE INDEX IF NOT EXISTS ohom_idx_msg_id on 
ofono_history_outgoing_messages (ohom_msg_id ASC);
diff --git a/plugins/sqlite_history.c b/plugins/sqlite_history.c
new file mode 100644
index 000..35dce71
--- /dev/null
+++ b/plugins/sqlite_history.c
@@ -0,0 +1,301 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010 Dario 'Djdas' Conigliaro.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include stdlib.h
+#include string.h
+#include glib.h
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include ofono/plugin.h
+#include ofono/log.h
+#include ofono/history.h
+#include ofono/types.h
+#include ofono/modem.h
+
+#include common.h
+
+#include sqlite3.h
+
+#define SQL_HISTORY_DB_PATH STORAGEDIR /ofono_history.sqlite
+#define SQL_HISTORY_DB_SQL STORAGEDIR /oFono_History_DB.sql
+
+#define SELECT_CALLS SELECT * FROM ofono_history_calls
+#define INSERT_CALLS INSERT INTO ofono_history_calls VALUES (?,?,?,?,?,?)
+#define INSERT_IN_MSGS INSERT INTO ofono_history_incoming_messages VALUES 
(?,?,?,?,?,?)
+#define INSERT_OUT_MSGS INSERT INTO ofono_history_outgoing_messages VALUES 
(?,?,?,?,?,?,?)
+#define UPDATE_OUT_MSGS UPDATE ofono_history_outgoing_messages SET \
+   ohom_send_status = ?, \
+   ohom_status_update_date 
= ? \
+   WHERE ohom_msg_id = ?
+
+sqlite3 *db = NULL;
+
+static int sqlite_history_probe(struct ofono_history_context *context)
+{
+   char *execerror;
+
+   ofono_debug(SQLite History Probe for modem: %p, context-modem);
+   
+   if (sqlite3_open(SQL_HISTORY_DB_PATH, db) != SQLITE_OK) {
+   ofono_debug(Error opening DB: %s, sqlite3_errmsg(db));
+   sqlite3_close(db);
+   return -1;
+   }
+
+   if (sqlite3_exec(db, SELECT_CALLS, NULL, NULL, execerror) != 
SQLITE_OK) {
+   char *sqlscript;
+   GError *sqlerror = NULL;
+
+   ofono_debug(Creating DB);
+
+   g_file_get_contents(SQL_HISTORY_DB_SQL, sqlscript, NULL, 
sqlerror);
+   
+   if (sqlerror != NULL) {
+   ofono_debug(Error opening sql script: %s, 
sqlerror-message);
+   g_error_free(sqlerror);
+   return -1;
+   }
+   
+   if (sqlite3_exec(db, sqlscript, NULL, NULL, 

Re: [PATCH 2/2] Added SQLite history plugin

2010-04-06 Thread Dario

Bastian, Waldo ha scritto:

The message handling in this patch seems to be vulnerable to SQL injection 
attacks. See http://en.wikipedia.org/wiki/SQL_injection

Cheers,
Waldo


Hi Waldo,
I didn't think of a message carrying an SQL injection :)
Honestly I would use prepared statement since start of the job but I 
didn't manage how to do them in SQLite but I agree with you they're more 
secure and the code is cleaner, so I converted the source to them after 
studying their use.

Thank you for your suggestion.
Best Regards,
Dario.

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


RE: [PATCH 2/2] Added SQLite history plugin

2010-04-06 Thread Bastian, Waldo
 Bastian, Waldo ha scritto:
  The message handling in this patch seems to be vulnerable to SQL
 injection attacks. See http://en.wikipedia.org/wiki/SQL_injection
 
  Cheers,
  Waldo
 
 Hi Waldo,
 I didn't think of a message carrying an SQL injection :)
 Honestly I would use prepared statement since start of the job but I
 didn't manage how to do them in SQLite but I agree with you they're more
 secure and the code is cleaner, so I converted the source to them after
 studying their use.

Thanks, much better :-)

Cheers,
Waldo
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH 2/2] Added SQLite history plugin

2010-04-06 Thread Denis Kenzior
Hi Dario,

 +#define SQL_HISTORY_DB_PATH STORAGEDIR /ofono_history.sqlite
 +#define SQL_HISTORY_DB_SQL STORAGEDIR /oFono_History_DB.sql

So I have my concerns about storing this in /.  This should be in a proper 
directory, like /var/lib/ofono or something like that.

 +static int sqlite_history_probe(struct ofono_history_context *context)
 +{
 + char *execerror;
 +
 + ofono_debug(SQLite History Probe for modem: %p, context-modem);
 +
 + if (sqlite3_open(SQL_HISTORY_DB_PATH, db) != SQLITE_OK) {
 + ofono_debug(Error opening DB: %s, sqlite3_errmsg(db));

Please use DBG macro instead of ofono_debug.

 + sqlite3_close(db);
 + return -1;
 + }
 +
 + if (sqlite3_exec(db, SELECT_CALLS, NULL, NULL, execerror) != SQLITE_OK)
  { +  char *sqlscript;

Should be

if (sqlite3_exec == SQLITE_OK)
return 0;

Then the rest of the if statement follows unnested.
 + GError *sqlerror = NULL;
 +
 + ofono_debug(Creating DB);
 +
 + g_file_get_contents(SQL_HISTORY_DB_SQL, sqlscript, NULL, 
 sqlerror);
 +
 + if (sqlerror != NULL) {
 + ofono_debug(Error opening sql script: %s, 
 sqlerror-message);
 + g_error_free(sqlerror);
 + return -1;
 + }
 +
 + if (sqlite3_exec(db, sqlscript, NULL, NULL, execerror) != 
 SQLITE_OK) {
 + ofono_debug(Error executing sql script: %s, 
 execerror);
 + sqlite3_free(execerror);
 + g_free(sqlscript);
 + return -1;
 + }
 +
 + g_free(sqlscript);
 + }
 +
 + return 0;
 +}
 +
 +static void sqlite_history_remove(struct ofono_history_context *context)
 +{
 + ofono_debug(SQLite History Remove for modem: %p, context-modem);
 +
 + if (db != NULL)
 + sqlite3_close(db);
 +}
 +

So remember that the history plugin is instantiated for each and every modem, 
so you will be sqlite_open/sqlite_closing the db in each instance.  Not really 
sure if this is what you want, or whether you want a reference-counted 
database connection here.

Another thing to consider is that you might want to store the IMSI of the 
modem along with the history information for every call / sms event.  That way 
when a SIM card is changed, the user can be shown a different set of call / sms 
 
history.

Finally, you might want to set limits on the number of entries in the 
database, and expire them as the limit is reached.   Otherwise you'd need to 
expire them periodically from e.g. cron, but would need to release control of 
the database during that time.

Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono