NVM changes in libtcore
authorParesh Agarwal <paresh.agwl@samsung.com>
Thu, 10 Jan 2013 09:16:54 +0000 (14:46 +0530)
committerwootak.jung <wootak.jung@samsung.com>
Sun, 24 Mar 2013 09:03:04 +0000 (18:03 +0900)
include/at.h [changed mode: 0644->0755]
src/at.c [changed mode: 0644->0755]
src/co_modem.c [changed mode: 0644->0755]
src/mux.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index e4f8abf..e6db17f
@@ -26,6 +26,8 @@ __BEGIN_DECLS
 #include <tcore.h>
 #include <queue.h>
 
+#define ZERO                                                           0
+
 enum tcore_at_command_type {
     TCORE_AT_NO_RESULT,   /* no intermediate response expected */
     TCORE_AT_NUMERIC,     /* a single intermediate response starting with a 0-9 */
@@ -102,6 +104,10 @@ typedef gboolean (*TcoreATNotificationCallback)(TcoreAT *at, const GSList *lines
 typedef struct tcore_at_response TcoreATResponse;
 typedef struct tcore_at_request TcoreATRequest;
 
+void tcore_at_process_binary_data(TcoreAT *at,char *position,int data_len);
+int sum_4_bytes(char* posn);
+
+gboolean tcore_at_add_hook(TcoreHal *hal, void *hook_func);
 TcoreAT*         tcore_at_new(TcoreHal *hal);
 void             tcore_at_free(TcoreAT *at);
 
old mode 100644 (file)
new mode 100755 (executable)
index 4a7d902..0c4037a
--- a/src/at.c
+++ b/src/at.c
 #include "user_request.h"
 #include "at.h"
 
-#define NUM_ELEMS(x) (sizeof(x) / sizeof(x[0]))
+#define NUM_ELEMS(x) (sizeof(x)/sizeof(x[0]))
+#define MODE_HEX       0
+#define MODE_BIN       1
 
 #define CR '\r'
 #define LF '\n'
 
-#define MAX_AT_RESPONSE    255  // for testing
-// #define MAX_AT_RESPONSE    8191
+#define MAX_AT_RESPONSE    255
+
+typedef gboolean (*rfs_hook_cb) (const char *data);
 
 struct tcore_at_type {
        TcoreHal *hal;
@@ -57,6 +60,9 @@ struct tcore_at_type {
        gboolean pdu_status;
        struct _notification *pdu_noti;
        GSList *pdu_lines;
+
+       rfs_hook_cb rfs_hook;
+       gboolean data_mode;
 };
 
 struct _notification_callback {
@@ -197,6 +203,7 @@ static void _emit_unsolicited_message(TcoreAT *at, const char *line)
        if (!at || !line)
                return;
 
+       dbg("at->pdu_status  %d line 0x%x at->data_mode %d", at->pdu_status, line, at->data_mode);
        if (at->pdu_status == FALSE) {
                g_hash_table_iter_init(&iter, at->unsolicited_table);
 
@@ -219,13 +226,25 @@ static void _emit_unsolicited_message(TcoreAT *at, const char *line)
                        return;
                }
 
-               data = g_slist_append(NULL, g_strdup(line));
-       } else {
+               if (at->data_mode == MODE_BIN) {
+                       at->pdu_lines = g_slist_append(at->pdu_lines, (gpointer)line);
+                       data = at->pdu_lines;
+               } else {
+                       data = g_slist_append(NULL, g_strdup(line));
+               }
+       }
+       else {
                noti = at->pdu_noti;
                at->pdu_status = FALSE;
                at->pdu_noti = NULL;
-               at->pdu_lines = g_slist_append(at->pdu_lines, g_strdup(line));
 
+               if (at->data_mode == MODE_BIN) {
+                       dbg("Binary mode");
+                       at->pdu_lines = g_slist_append(at->pdu_lines, (gpointer)line);
+                       dbg("at->pdu_lines: 0x%x", at->pdu_lines);
+               } else {
+                       at->pdu_lines = g_slist_append(at->pdu_lines, g_strdup(line));
+               }
                data = at->pdu_lines;
        }
 
@@ -246,14 +265,15 @@ static void _emit_unsolicited_message(TcoreAT *at, const char *line)
 
                p = p->next;
        }
-
-
-       g_slist_free_full(data, g_free);
+       dbg(" Free the list");
+       if (at->data_mode != MODE_BIN) {
+               g_slist_free_full(data, g_free);
+       }
        at->pdu_lines = NULL;
-
        if (g_slist_length(noti->callbacks) == 0) {
                g_hash_table_remove(at->unsolicited_table, key);
        }
+       dbg("exit");
 }
 
 static void _free_noti_list(void *data)
@@ -314,7 +334,7 @@ TcoreAT* tcore_at_new(TcoreHal *hal)
        at->buf = calloc(at->buf_size + 1, 1);
        at->buf_read_pos = at->buf;
        at->buf_write_pos = at->buf;
-
+       at->data_mode = MODE_HEX;
        at->unsolicited_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _free_noti_list);
        return at;
 }
@@ -502,11 +522,11 @@ TReturn tcore_at_buf_write(TcoreAT *at, unsigned int data_len, const char *data)
                        if (at->buf_size > write_pos + data_len)
                                break;
                }
+
                at->buf = realloc(at->buf, at->buf_size);
                at->buf_read_pos = at->buf;
                at->buf_write_pos = at->buf + write_pos;
                memset(at->buf_write_pos, 0, at->buf_size - (at->buf_write_pos - at->buf));
-
                dbg("resize buffer to %d", at->buf_size);
        }
 
@@ -558,6 +578,48 @@ void tcore_at_request_free(TcoreATRequest *req)
        free(req);
 }
 
+/* To get the length value from little-endian bytes */
+static int __sum_4_bytes(const char *posn)
+{
+       int sum = 0;
+       sum = sum | (*(posn+3)) << 24;
+       sum = sum | (*(posn+2)) << 16;
+       sum = sum | (*(posn+1)) << 8;
+       sum = sum | *posn ;
+       return sum;
+}
+
+/* Function to process binary data received as part of XDRV Indication */
+void tcore_at_process_binary_data(TcoreAT *at, char *position, int data_len)
+{
+
+       #define NVM_PAYLOAD_LENGTH_0                    52
+       #define NVM_PAYLOAD_LENGTH_1                    68
+
+       int m_length_0 = ZERO , m_length_1 = ZERO;
+       static int data_len_final = ZERO, actual_buffer_size = ZERO;
+       dbg("Entered");
+
+       m_length_0 = __sum_4_bytes(&position[NVM_PAYLOAD_LENGTH_0]);
+       m_length_1 = __sum_4_bytes(&position[NVM_PAYLOAD_LENGTH_1]);
+       data_len_final = data_len_final + data_len;
+
+       dbg("m_length_0 = %d , m_length_1 = %d, data_len_final = %d actual_buffer_size: %d", m_length_0, m_length_1, data_len_final, actual_buffer_size);
+       if (actual_buffer_size == ZERO) {
+               actual_buffer_size = data_len + m_length_0 + m_length_1;
+               dbg("Actual buffer size is %d", actual_buffer_size);
+       }
+
+       if (data_len_final == actual_buffer_size) {
+               _emit_unsolicited_message(at, position);
+               at->data_mode = MODE_HEX;
+               at->buf_read_pos = at->buf_read_pos + (actual_buffer_size + 1);
+               data_len_final = ZERO;
+               actual_buffer_size = ZERO;
+       }
+       dbg("Exit");
+}
+
 gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data)
 {
        char *pos;
@@ -570,6 +632,7 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data)
        tcore_at_buf_write(at, data_len, data);
 
        pos = at->buf_read_pos;
+       dbg("On entry at->buf_read_pos: 0x%x", at->buf_read_pos);
 
        while (1) {
                while (*pos == CR || *pos == LF)
@@ -577,8 +640,18 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data)
 
                next_pos = _find_next_EOL(pos);
                if (!next_pos)
+               {
+                       dbg("Data could be in Binary mode !!");
+                       if (at->rfs_hook) {
+                               if (TRUE == at->rfs_hook(pos)){
+                                       at->data_mode = MODE_BIN;
+                                       tcore_at_process_binary_data(at, pos, data_len);
+                               }
+                               dbg("Not Binary data");
+                       }
+                       dbg("Rfs hook is not set !!");
                        break;
-
+               }
                if (pos != next_pos)
                        *next_pos = '\0';
 
@@ -586,8 +659,11 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data)
                dbg("line = [%s]", pos);
                // check request
                if (!at->req) {
+                       dbg(" Not At request " );
                        _emit_unsolicited_message(at, pos);
-               } else {
+               }
+               else {
+
                        if (g_strcmp0(pos, "> ") == 0) {
                                if (at->req->next_send_pos) {
                                        dbg("send next: [%s]", at->req->next_send_pos);
@@ -629,21 +705,24 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data)
 
                                        break;
 
-                               case TCORE_AT_SINGLELINE:
-                                       if (at->resp->lines == NULL) {
-                                               if (at->req->prefix) {
-                                                       if (g_str_has_prefix(pos, at->req->prefix)) {
-                                                               _response_add(at->resp, pos);
+                                       case TCORE_AT_SINGLELINE:
+                                               dbg("Type is SINGLELINE");
+                                               if (at->resp->lines == NULL) {
+                                                       if (at->req->prefix) {
+                                                               if (g_str_has_prefix(pos, at->req->prefix)) {
+                                                                               _response_add(at->resp, pos);
+                                                               }
+                                                               else {
+                                                                       _emit_unsolicited_message(at, pos);
+                                                               }
                                                        } else {
-                                                               _emit_unsolicited_message(at, pos);
+                                                               _response_add(at->resp, pos);
                                                        }
-                                               } else {
-                                                       _response_add(at->resp, pos);
                                                }
-                                       } else {
-                                               _emit_unsolicited_message(at, pos);
-                                       }
-                                       break;
+                                               else {
+                                                       _emit_unsolicited_message(at, pos);
+                                               }
+                                               break;
 
                                case TCORE_AT_MULTILINE:
                                        if (at->req->prefix) {
@@ -685,7 +764,7 @@ gboolean tcore_at_process(TcoreAT *at, unsigned int data_len, const char *data)
                pos = next_pos + 1;
                at->buf_read_pos = pos;
        }
-
+       dbg("On exit at->buf_read_pos: 0x%x", at->buf_read_pos);
        return FALSE;
 }
 
@@ -879,3 +958,17 @@ char* tcore_at_tok_nth(GSList *tokens, unsigned int token_index)
 
        return (char *) g_slist_nth_data(tokens, token_index);
 }
+
+gboolean tcore_at_add_hook(TcoreHal *hal, void *hook_func)
+{
+       TcoreAT *at;
+       at = tcore_hal_get_at(hal);
+
+       if (at != NULL) {
+               dbg("Setting the rfs hook callback function");
+               at->rfs_hook = (rfs_hook_cb) hook_func;
+               return TRUE;
+       }
+       dbg("AT is NULL !!!");
+       return FALSE;
+}
old mode 100644 (file)
new mode 100755 (executable)
index 82b6488..cdd47d0
@@ -157,13 +157,12 @@ CoreObject *tcore_modem_new(TcorePlugin *p, const char *name,
        CoreObject *o = NULL;
        struct private_object_data *po = NULL;
 
+       //dbg("Entered");
        if (!p)
                return NULL;
-
        o = tcore_object_new(p, name, hal);
        if (!o)
                return NULL;
-
        po = calloc(sizeof(struct private_object_data), 1);
        if (!po) {
                tcore_object_free(o);
@@ -177,7 +176,6 @@ CoreObject *tcore_modem_new(TcorePlugin *p, const char *name,
        tcore_object_set_free_hook(o, _free_hook);
        tcore_object_set_clone_hook(o, _clone_hook);
        tcore_object_set_dispatcher(o, _dispatcher);
-
        return o;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 900115d..b62dc01
--- a/src/mux.c
+++ b/src/mux.c
@@ -850,10 +850,14 @@ static void tcore_cmux_process_rcv_frame(unsigned char *data, int len)
                ch->poll_final_bit = (ch->frame_type & 0x10) >> 4;
 
                // get the length . TBD
+               dbg("*frame_process_ptr: %02x", *frame_process_ptr);
+               dbg("*(frame_process_ptr+1): %02x", *(frame_process_ptr+1));
                if (*frame_process_ptr & 0x01) {                        // if, len < 127
+                       dbg("Length < 127");
                        g_mux_obj_ptr->info_field_len = *frame_process_ptr++ >> 1;
                        header_length = 3;
                } else {
+                       dbg("Length > 127");
                        g_mux_obj_ptr->info_field_len = *(frame_process_ptr + 1) << 7;
                        g_mux_obj_ptr->info_field_len = g_mux_obj_ptr->info_field_len | ((*frame_process_ptr++ & 0xFE) >> 1);
                        header_length = 4;