#include "core_object.h"
/* Maximum Core objects per Logical HAL (indirectly per Channel) */
-#define MAX_CMUX_CORE_OBJECTS 3\r
+#define MAX_CMUX_CORE_OBJECTS 3
-/* Max CMUX Buffer size */\r
-#define MAX_CMUX_BUFFER_SIZE 2000\r
+/* Max CMUX Buffer size */
+#define MAX_CMUX_BUFFER_SIZE 4096
-/* Max muber of CMUX Channels */\r
-#define MAX_CMUX_CHANNELS_SUPPORTED 8\r
+/* Max muber of CMUX Channels */
+#define MAX_CMUX_CHANNELS_SUPPORTED 8
-/* CMUX Commands */\r
-#define CMUX_COMMAND_SABM 0x2F\r
-#define CMUX_COMMAND_UA 0x63\r
-#define CMUX_COMMAND_DM 0x0F\r
-#define CMUX_COMMAND_DISC 0x43\r
-#define CMUX_COMMAND_UIH 0xEF\r
-#define CMUX_COMMAND_UI 0x03\r
+/* CMUX Commands */
+#define CMUX_COMMAND_SABM 0x2F
+#define CMUX_COMMAND_UA 0x63
+#define CMUX_COMMAND_DM 0x0F
+#define CMUX_COMMAND_DISC 0x43
+#define CMUX_COMMAND_UIH 0xEF
+#define CMUX_COMMAND_UI 0x03
-/* MUX CONTROL COMMANDS
+/* MUX CONTROL COMMANDS
* We are supporting only MSC command for phase 1
*/
-#define CMUX_COMMAND_MSC 0xE3 //Modem Status Command\r
-#define CMUX_COMMAND_CLD 0xC3 //Multiplexer close down\r
-#if 0 /* Support in Phase 2 */\r
-#define CMUX_COMMAND_PN //Parameter Negotiation\r
-#define CMUX_COMMAND_PSC //Power Saving Control\r
-#define CMUX_COMMAND_TEST //Test Command\r
-#define CMUX_COMMAND_NSC //Non Supported Command Response\r
-#define CMUX_COMMAND_RPN //Remote Port Negotiation Command\r
-#define CMUX_COMMAND_RLS //Remote Line Status Command\r
-#define CMUX_COMMAND_SNC //Service Negotiation Command\r
-#endif /* Support in Phase 2 */\r
+#define CMUX_COMMAND_MSC 0xE3 // Modem Status Command
+#define CMUX_COMMAND_CLD 0xC3 // Multiplexer close down
/* CMUX Channels [0-7] -
* Channel 0 - Control Channel for CMUX
* Channel 1 - CALL
- * Channel 2 - SIM
+ * Channel 2 - SIM
* Channel 3 - SAT
* Channel 4 - SMS
* Channel 5 - SS
CMUX_CHANNEL_7
} CMUX_Channels;
-/* MUX Channel States */\r
+/* MUX Channel States */
typedef enum MuxChannelState {
MUX_CHANNEL_CLOSED,
MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA,
MUX_CHANNEL_ESTABLISHED,
MUX_CHANNEL_UA_NOT_RECEIVED_RETRY,
MUX_CHANNEL_DM_RECEIVED_CLOSING,
- MUX_CHANNEL_DM_SEND,
+ MUX_CHANNEL_DM_SEND,
MUX_CHANNEL_DISC_RECEIVED_CLOSING,
- MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA,
- MUX_CHANNEL_UA_SEND_CLOSING,
+ MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA,
+ MUX_CHANNEL_UA_SEND_CLOSING,
MUX_CHANNEL_UA_RECEIVED,
- MUX_CHANNEL_UA_SENDING,
-
+ MUX_CHANNEL_UA_SENDING,
} MuxChannelState;
-/* MUX State */\r
+/* MUX State */
typedef enum MuxState {
MUX_NOT_INITIALIZED,
MUX_INITIALIZED,
MUX_CLOSED
} MuxState;
-#define FIND_LENGTH(buf, header_length, total_length) do{ \\r
- if (*buf & 0x01) { \
- total_length = *buf++ >>1; \\r
- header_length=6; \\r
- } \
- else { \
- total_length = *(buf + 0x01) << 7; \\r
- total_length = total_length | (*buf & 0xFE) >> 1; \\r
- header_length = 7; \\r
- } \
- } while(0)
+#define FIND_LENGTH(buf, header_length, total_length) do { \
+ if (*buf & 0x01) { \
+ total_length = *buf++ >> 1; \
+ header_length = 6; \
+ } \
+ else { \
+ total_length = *(buf + 0x01) << 7; \
+ total_length = total_length | (*buf & 0xFE) >> 1; \
+ header_length = 7; \
+ } \
+} while (0)
/*================= CRC TABLE=========================*/
-const unsigned char crc_table[256] = { //reversed, 8-bit, poly=0x07\r
+const unsigned char crc_table[256] = { // reversed, 8-bit, poly=0x07
0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B,
0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69, 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67,
0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, 0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43,
};
/*================= CRC TABLE=========================*/
-/* CMUX Channel */\r
-typedef struct cmux_channel {
- GSList *co;
+/* CMUX Channel */
+typedef struct cmux_channel {
+ GSList *co;
TcoreHal *hal;
-
- MuxChannelState state;
- CMUX_Channels channel_id;\r
- int frame_type;\r
- unsigned char ext_bit;\r
- unsigned char cr_bit;\r
- unsigned char poll_final_bit;\r
+ MuxChannelState state;
+ CMUX_Channels channel_id;
+ int frame_type;
+ unsigned char ext_bit;
+ unsigned char cr_bit;
+ unsigned char poll_final_bit;
} CHANNEL;
-/* CMUX callback prototype */\r
+/* CMUX callback prototype */
typedef gboolean (*mux_cb_func)(CHANNEL *channel_ptr);
-/* CMUX structure */\r
+/* CMUX structure */
typedef struct cmux {
MuxState state;
-
- CHANNEL *channel_info[MAX_CMUX_CHANNELS_SUPPORTED];\r
- int is_waiting;\r
- int msg_len;\r
- int cur_main_buf_len;\r
-
- /* Plugin */
- TcorePlugin *plugin;\r
-
- /* Physical HAL */
+ CHANNEL *channel_info[MAX_CMUX_CHANNELS_SUPPORTED];
+ int is_waiting;
+ int msg_len;
+ int cur_main_buf_len;
+ TcorePlugin *plugin;
TcoreHal *phy_hal;
-
- /* Modem Core Object */
CoreObject *modem_co;
-
- mux_cb_func cb_func;
-
- /* Resolve Crash issue*/
- int info_field_len;\r
- /*Information field*/
- unsigned char *info_field;\r
-
- unsigned char *mux_temp_buffer;\r
- unsigned char *mux_main_buffer;\r
+ mux_cb_func cb_func;
+ int info_field_len;
+ unsigned char *info_field;
} MUX;
/* Global pointer MUX Object pointer */
-MUX *g_mux_obj_ptr = NULL;\r
+MUX *g_mux_obj_ptr = NULL;
/* CMUX mode of operation */
-int g_mux_mode = 0; /* BASIC mode */\r
+int g_mux_mode = 0; /* BASIC mode */
struct cmux_channel_object {
char *channel_id_name;
- char *core_object_name[MAX_CMUX_CORE_OBJECTS];\r
+ char *core_object_name[MAX_CMUX_CORE_OBJECTS];
};
/* Core Object names need to be verified, define a MACRO globally */
-struct cmux_channel_object cmux_channel_core_object[] = {\r
- {"channel_0", {"control", NULL, NULL}},
- {"channel_1", {"call", NULL, NULL}},
- {"channel_2", {"sim", NULL, NULL}},
- {"channel_3", {"sat", NULL, NULL}},
- {"channel_4", {"umts_sms", NULL, NULL}},
- {"channel_5", {"ss", NULL, NULL}},
- {"channel_6", {"umts_network", NULL, NULL}},
- {"channel_7", {"modem", "umts_ps", NULL}},
+struct cmux_channel_object cmux_channel_core_object[] = {
+ {"channel_0", {"control", NULL, NULL}},
+ {"channel_1", {"call", NULL, NULL}},
+ {"channel_2", {"sim", NULL, NULL}},
+ {"channel_3", {"sat", NULL, NULL}},
+ {"channel_4", {"umts_sms", NULL, NULL}},
+ {"channel_5", {"ss", NULL, NULL}},
+ {"channel_6", {"umts_network", NULL, NULL}},
+ {"channel_7", {"modem", "umts_ps", NULL}},
};
/* All the local functions declared below */
-static unsigned char calc_crc(unsigned char *header , int length);
-static int rcv_crc_check(unsigned char *data, unsigned char len,unsigned char rcv_FCS);\r
-
-MUX *tcore_cmux_new(void);
-static void tcore_cmux_free(void);\r
-
+static unsigned char calc_crc(unsigned char *header, int length);
+static int rcv_crc_check(unsigned char *data, unsigned char len, unsigned char rcv_FCS);
+MUX* tcore_cmux_new(void);
+static void tcore_cmux_free(void);
void tcore_cmux_link_core_object_hal(CMUX_Channels channel_id, TcorePlugin *plugin);
-static gboolean tcore_cmux_recv_mux_data(CHANNEL* channel_ptr);
-static void tcore_cmux_process_rcv_frame( unsigned char *data, int len);
-static void tcore_cmux_process_channel_data(CHANNEL *channel_info_ptr);\r
-static void tcore_cmux_control_channel_handle(void);\r
-static void tcore_cmux_flush_channel_data(void);\r
-
-static void tcore_cmux_channel_init(CMUX_Channels channel_id);\r
-static void tcore_cmux_close_channel(int channel_id);\r
-
-static unsigned char *tcore_encode_cmux_frame(unsigned char *data,
- int length,
- int channel_id,
- int frame_type,\r
- unsigned char EA_bit,\r
- unsigned char CR_bit,\r
- unsigned char PF_bit,\r
- int *out_data_len);
-\r
-static TReturn tcore_cmux_send_data(int data_len, unsigned char *data);\r
+static gboolean tcore_cmux_recv_mux_data(CHANNEL *channel_ptr);
+static void tcore_cmux_process_rcv_frame(unsigned char *data, int len);
+static void tcore_cmux_process_channel_data(CHANNEL *channel_info_ptr);
+static void tcore_cmux_control_channel_handle(void);
+static void tcore_cmux_flush_channel_data(void);
+static void tcore_cmux_channel_init(CMUX_Channels channel_id);
+static void tcore_cmux_close_channel(int channel_id);
+static unsigned char* tcore_encode_cmux_frame(unsigned char *data, int length, int channel_id, int frame_type, unsigned char EA_bit, unsigned char CR_bit, unsigned char PF_bit, int *out_data_len);
+static TReturn tcore_cmux_send_data(int data_len, unsigned char *data);
static TReturn tcore_cmux_hal_power(TcoreHal *h, gboolean flag)
{
- TcorePlugin *p = NULL;\r
- struct custom_data *user_data = NULL;\r
+ TcorePlugin *p = NULL;
+ struct custom_data *user_data = NULL;
+
dbg("Entry");
p = tcore_hal_ref_plugin(h);
static TReturn tcore_cmux_hal_send(TcoreHal *h, unsigned int data_len, void *data)
{
- unsigned char *send_data= NULL;
+ unsigned char *send_data = NULL;
char *channel_name = NULL;
- int channel_id = MAX_CMUX_CHANNELS_SUPPORTED;\r
+ int channel_id = MAX_CMUX_CHANNELS_SUPPORTED;
int len = 0;
int i = 0;
-
int ret;
+
dbg("Entry");
- dbg("data: %s", (char *)data);
/* Check if Logical HAL is Powered ON */
if (tcore_hal_get_power_state(h) == FALSE) {
channel_name = tcore_hal_get_name(h);
dbg("HAL name: %s", channel_name)
- if(channel_name) {
- while(i < MAX_CMUX_CHANNELS_SUPPORTED) {\r
- dbg("HAL name of Channels: %s", cmux_channel_core_object[i].channel_id_name);\r
- if (0 == strcmp((char *)cmux_channel_core_object[i].channel_id_name, (char *)channel_name)) {\r
+ if (channel_name) {
+ while (i < MAX_CMUX_CHANNELS_SUPPORTED) {
+ if (0 == strcmp((char *) cmux_channel_core_object[i].channel_id_name, (char *) channel_name)) {
channel_id = i;
dbg("Found Channel ID: %d", channel_id);
}
i++;
}
- }
- else {
+ } else {
err("No name defined for HAL");
return TCORE_RETURN_FAILURE;
}
- if(channel_id > MAX_CMUX_CHANNELS_SUPPORTED) {\r
+ if (channel_id > MAX_CMUX_CHANNELS_SUPPORTED) {
err("Failed to find Channel ID");
return TCORE_RETURN_FAILURE;
}
-
+
/* Muxing operation and Frame creation */
/* Encoding frame */
- send_data = tcore_encode_cmux_frame(data, data_len, channel_id, CMUX_COMMAND_UIH, 1, 1, 0, &len);\r
- if(0 == len) {\r
+ send_data = tcore_encode_cmux_frame(data, data_len, channel_id, CMUX_COMMAND_UIH, 1, 1, 0, &len);
+ if (0 == len) {
err("Failed to encode");
return TCORE_RETURN_FAILURE;
}
-
- /* Send CMUX data */\r
- ret = tcore_cmux_send_data(len, send_data);\r
-
+
+ /* Send CMUX data */
+ ret = tcore_cmux_send_data(len, send_data);
+
dbg("Exit");
return TCORE_RETURN_SUCCESS;
}
/* CMUX supported HAL (Logical HAL) operations */
-static struct tcore_hal_operations mux_hops =
-{
+static struct tcore_hal_operations mux_hops = {
.power = tcore_cmux_hal_power,
.send = tcore_cmux_hal_send,
};
-static TReturn tcore_cmux_send_data(int data_len, unsigned char *data)\r
-{\r
- TReturn ret = TCORE_RETURN_SUCCESS;\r
- dbg("Entry");\r
-\r
- /* Directly send to Physical HAL */\r
- ret = tcore_hal_send_data(g_mux_obj_ptr->phy_hal, data_len, (void *)data);\r
- if(TCORE_RETURN_SUCCESS != ret) {\r
- err("Failed to send CMUX data");\r
- }\r
- else{\r
- dbg("Successfully sent CMUX data");\r
- }\r
-\r
- dbg("Exit");\r
- return ret;\r
-}\r
+static TReturn tcore_cmux_send_data(int data_len, unsigned char *data)
+{
+ TReturn ret = TCORE_RETURN_SUCCESS;
+
+ dbg("Entry");
+
+ /* Directly send to Physical HAL */
+ ret = tcore_hal_send_data(g_mux_obj_ptr->phy_hal, data_len, (void *) data);
+ if (TCORE_RETURN_SUCCESS != ret) {
+ err("Failed to send CMUX data");
+ } else {
+ dbg("Successfully sent CMUX data");
+ }
+
+ dbg("Exit");
+ return ret;
+}
static gboolean tcore_cmux_recv_mux_data(CHANNEL *channel_ptr)
{
TcoreHal *hal = NULL;
+
dbg("Entry");
/* Dereferencing HAL from Channel Pointer */
hal = channel_ptr->hal;
-
+
dbg("Dispatching to logical HAL - hal: %x", hal);
- tcore_hal_dispatch_response_data(hal, 0, g_mux_obj_ptr->info_field_len, g_mux_obj_ptr->info_field);\r
+ tcore_hal_dispatch_response_data(hal, 0, g_mux_obj_ptr->info_field_len, g_mux_obj_ptr->info_field);
dbg("Exit");
return TRUE;
TcoreHal *hal = NULL;
CoreObject *co = NULL;
int index;
+
dbg("Entry");
- if(CMUX_CHANNEL_0 != channel_id) {
+ if (CMUX_CHANNEL_0 != channel_id) {
dbg("Normal channel [%d]", channel_id);
-
+
/* Creating Logical HAL for Core Object - Mode - 'AT mode' */
- hal = tcore_hal_new(plugin, cmux_channel_core_object[channel_id].channel_id_name, &mux_hops, TCORE_HAL_MODE_AT);\r
+ hal = tcore_hal_new(plugin, cmux_channel_core_object[channel_id].channel_id_name, &mux_hops, TCORE_HAL_MODE_AT);
dbg("hal: %p", hal);
-
+
/* Update Logical HAL of CMUX Channel */
- g_mux_obj_ptr->channel_info[channel_id]->hal = hal;\r
-
+ g_mux_obj_ptr->channel_info[channel_id]->hal = hal;
+
index = 0;
- while (NULL != cmux_channel_core_object[channel_id].core_object_name[index]) {\r
+ while (NULL != cmux_channel_core_object[channel_id].core_object_name[index]) {
/* Retrieving Core Object */
- dbg("Core Object: '%s'", cmux_channel_core_object[channel_id].core_object_name[index]);\r
- co = tcore_plugin_ref_core_object(plugin, cmux_channel_core_object[channel_id].core_object_name[index]);\r
+ dbg("Core Object: '%s'", cmux_channel_core_object[channel_id].core_object_name[index]);
+ co = tcore_plugin_ref_core_object(plugin, cmux_channel_core_object[channel_id].core_object_name[index]);
dbg("co: %p", co);
- if (0 == strcmp((const char *)cmux_channel_core_object[channel_id].core_object_name[index], "modem")) {\r
- g_mux_obj_ptr->modem_co = co;\r
+ if (0 == strcmp((const char *) cmux_channel_core_object[channel_id].core_object_name[index], "modem")) {
+ g_mux_obj_ptr->modem_co = co;
dbg("'modem' Core object reference is stored");
}
tcore_object_set_hal(co, hal);
/* Update Core Object list of CMUX Channel */
- g_mux_obj_ptr->channel_info[channel_id]->co = g_slist_append(g_mux_obj_ptr->channel_info[channel_id]->co, co);\r
+ g_mux_obj_ptr->channel_info[channel_id]->co = g_slist_append(g_mux_obj_ptr->channel_info[channel_id]->co, co);
- /* Next Core Object of the channel */\r
+ /* Next Core Object of the channel */
index++;
- };
- }
- else {
+ }
+ } else {
/* Control Channel */
dbg("Control channel");
-
+
/* Creating Logical HAL for Core Object - Mode - 'AT mode' */
- hal = tcore_hal_new(plugin, cmux_channel_core_object[channel_id].channel_id_name, &mux_hops, TCORE_HAL_MODE_AT);\r
+ hal = tcore_hal_new(plugin, cmux_channel_core_object[channel_id].channel_id_name, &mux_hops, TCORE_HAL_MODE_AT);
dbg("hal: %p", hal);
-
+
/* Update Logical HAL of CMUX Channel */
- g_mux_obj_ptr->channel_info[channel_id]->hal = hal;\r
+ g_mux_obj_ptr->channel_info[channel_id]->hal = hal;
}
/* Set Logical HAL Power State to TRUE */
tcore_hal_set_power_state(hal, TRUE);
dbg("HAL Power is SET");
-
+
dbg("Exit");
return;
}
-MUX *tcore_cmux_new(void)
+MUX* tcore_cmux_new(void)
{
- MUX *mux = NULL;\r
+ MUX *mux = NULL;
int i = 0;
- dbg("Entry");
-
- /* Allocating memory for mux */\r
- mux = (MUX*)calloc(sizeof(MUX), 1);\r
- if (!mux) {\r
+
+ /* Allocating memory for mux */
+ mux = (MUX *) calloc(sizeof(MUX), 1);
+ if (!mux) {
err("Failed to allocate memory");
return NULL;
}
- /* Allocating memory for info_field */\r
- mux->info_field = (unsigned char *)calloc(MAX_CMUX_BUFFER_SIZE, 1); \r
- if (!mux->info_field) {\r
+ /* Allocating memory for info_field */
+ mux->info_field = (unsigned char *) calloc(MAX_CMUX_BUFFER_SIZE, 1);
+ if (!mux->info_field) {
err("Failed to allocate memory for info field");
goto ERROR;
}
-
- /* Allocating memory for mux_temp_buffer */\r
- mux->mux_temp_buffer = (unsigned char *)calloc(MAX_CMUX_BUFFER_SIZE, 1); \r
- if (!mux->mux_temp_buffer) {\r
- err("Failed to allocate memory for info field");
- goto ERROR;
- }
-
- /* Allocating memory for mux_main_buffer */\r
- mux->mux_main_buffer = (unsigned char *)calloc(MAX_CMUX_BUFFER_SIZE, 1);\r
- if (!mux->mux_main_buffer) {\r
- err("Failedto allocate memory for info field");
- goto ERROR;
- }
-
- /* MUX State initialize to MUX_NOT_INITIALIZED */\r
- mux->state = MUX_NOT_INITIALIZED;\r
- /* Allocating memory for channel_info */\r
- for(i = 0 ; i < MAX_CMUX_CHANNELS_SUPPORTED ; i++) {\r
- mux->channel_info[i] = (CHANNEL*)calloc(sizeof(CHANNEL), 1);\r
+ /* MUX State initialize to MUX_NOT_INITIALIZED */
+ mux->state = MUX_NOT_INITIALIZED;
+
+ /* Allocating memory for channel_info */
+ for (i = 0; i < MAX_CMUX_CHANNELS_SUPPORTED; i++) {
+ mux->channel_info[i] = (CHANNEL *) calloc(sizeof(CHANNEL), 1);
/* Check for Memory allocation failure */
- if(!mux->channel_info[i]) {\r
- err("Failed to allocate memory for channel_info of channel: %d", i);\r
+ if (!mux->channel_info[i]) {
+ err("Failed to allocate memory for channel_info of channel: %d", i);
goto ERROR;
}
}
- dbg("Exit");
- return mux;\r
+ return mux;
ERROR:
/* Free allocated memory */
- if(mux) {\r
- if(mux->info_field) {\r
- free(mux->info_field);\r
- }
-
- if(mux->mux_temp_buffer) {\r
- free(mux->mux_temp_buffer);\r
- }
-
- if(mux->mux_main_buffer) {\r
- free(mux->mux_main_buffer);\r
+ if (mux) {
+ if (mux->info_field) {
+ free(mux->info_field);
}
- for(i = 0; i < MAX_CMUX_CHANNELS_SUPPORTED ; i++) {\r
- if(mux->channel_info[i]) {\r
- free(mux->channel_info[i]);\r
+ for (i = 0; i < MAX_CMUX_CHANNELS_SUPPORTED; i++) {
+ if (mux->channel_info[i]) {
+ free(mux->channel_info[i]);
}
}
- free(mux);\r
+ free(mux);
}
err("Exit");
return NULL;
}
-static unsigned char calc_crc (unsigned char *header , int length)
+static unsigned char calc_crc(unsigned char *header, int length)
{
- unsigned char FCS=0xFF; /*Init*/
- unsigned char crc = 0x00;\r
- dbg("Entry");\r
-
- /* 'length' is the number of bytes in the message, 'header' points to message */\r
+ unsigned char FCS = 0xFF; /*Init*/
+ unsigned char crc = 0x00;
+
+ /* 'length' is the number of bytes in the message, 'header' points to message */
while (length--) {
- FCS = crc_table[FCS ^ *header++];\r
+ FCS = crc_table[FCS ^ *header++];
}
-
+
/*Ones complement*/
- crc = (0xFF-FCS);\r
-\r
- dbg("Exit - crc: 0x%02x", crc)\r
- return crc;\r
+ crc = (0xFF - FCS);
+
+ dbg("Exit - crc: 0x%02x", crc)
+ return crc;
}
-static unsigned char *tcore_encode_cmux_frame(unsigned char *data,
- int length,
- int channel_id,
- int frame_type,\r
- unsigned char EA_bit,\r
- unsigned char CR_bit,\r
- unsigned char PF_bit,\r
- int *out_data_len)
+static unsigned char* tcore_encode_cmux_frame(unsigned char *data,
+ int length,
+ int channel_id,
+ int frame_type,
+ unsigned char EA_bit,
+ unsigned char CR_bit,
+ unsigned char PF_bit,
+ int *out_data_len)
{
- int frame_length = 0;\r
- int total_frame_length = 0;\r
- int crc_len =0;
+ int frame_length = 0;
+ int total_frame_length = 0;
+ int crc_len = 0;
+
dbg("Entry");
/* Flush channel data */
tcore_cmux_flush_channel_data();
- if(length > MAX_CMUX_BUFFER_SIZE ){
+ if (length > MAX_CMUX_BUFFER_SIZE) {
err("Length - %d exceeds the limit", length);
return NULL;
- }
+ }
+
+ /* Flag Octet */
+ g_mux_obj_ptr->info_field[frame_length++] = (char) 0xF9;
- /* Flag Octet */\r
- g_mux_obj_ptr->info_field[frame_length++] = (char)0xF9;\r
-\r
- /* Mode of Operation */\r
- if(0x00 == g_mux_mode) { /* BASIC */\r
+ /* Mode of Operation */
+ if (0x00 == g_mux_mode) { /* BASIC */
/* EA: Extension Bit
* C/R: Command Response
*/
- g_mux_obj_ptr->info_field[frame_length] = g_mux_obj_ptr->info_field[frame_length] | ((EA_bit & 0x01) | ((CR_bit << 1) & 0x02)); \r
+ g_mux_obj_ptr->info_field[frame_length] = g_mux_obj_ptr->info_field[frame_length] | ((EA_bit & 0x01) | ((CR_bit << 1) & 0x02));
/* DLCI: Data Link Connection Identifier */
/* Check if the channel is within range */
- if(channel_id < MAX_CMUX_CHANNELS_SUPPORTED && channel_id >=0) {\r
+ if (channel_id < MAX_CMUX_CHANNELS_SUPPORTED && channel_id >= 0) {
dbg("Channel ID: %d", channel_id);
- g_mux_obj_ptr->info_field[frame_length] = g_mux_obj_ptr->info_field[frame_length]|((unsigned char) channel_id << 2);\r
- }
- else {
+ g_mux_obj_ptr->info_field[frame_length] = g_mux_obj_ptr->info_field[frame_length] | ((unsigned char) channel_id << 2);
+ } else {
err("Channel is out of range[0-8]");
return NULL;
}
- frame_length++;\r
+ frame_length++;
/* Control Field
* The content of the control field defines the type of frame.
- * ****************************************************************\r
+ * ****************************************************************
* Frame Type 0 1 2 3 4 5 6 7
* SABM (Set Asynchronous Balanced Mode) 1 1 1 1 P/F 1 0 0
* UA (Unnumbered Acknowledgement) 1 1 0 0 P/F 1 1 0
* DM (Disconnected Mode) 1 1 1 1 P/F 0 0 0
* DISC (Disconnect) 1 1 0 0 P/F 0 1 0
* UIH (Unnumbered Information with Header check) 1 1 1 1 P/F 1 1 1
- *****************************************************************/\r
- if(PF_bit) {\r
- g_mux_obj_ptr->info_field[frame_length++] = frame_type |0x10;\r
- }
- else {
- g_mux_obj_ptr->info_field[frame_length++] = frame_type;\r
+ *****************************************************************/
+ if (PF_bit) {
+ g_mux_obj_ptr->info_field[frame_length++] = frame_type | 0x10;
+ } else {
+ g_mux_obj_ptr->info_field[frame_length++] = frame_type;
}
/* 5.2.1.5 Length Indicator */
if (length < 128) {
- g_mux_obj_ptr->info_field[frame_length++] = (char)length <<1|0x01;\r
-
+ g_mux_obj_ptr->info_field[frame_length++] = (char) length << 1 | 0x01;
+
/* CRC calculatable length */
crc_len = 3;
- }
- else {
- g_mux_obj_ptr->info_field[frame_length++] = (char)(length << 1); //Need to change\r
- g_mux_obj_ptr->info_field[frame_length++] = (char)(length >> 7); //Need to change \r
+ } else {
+ g_mux_obj_ptr->info_field[frame_length++] = (char) (length << 1); // Need to change
+ g_mux_obj_ptr->info_field[frame_length++] = (char) (length >> 7); // Need to change
/* CRC calculatable length */
crc_len = 4;
*/
/* 5.2.1.4 Information Field*/
- if(length >0) {
- dbg("MEMCPY :length= %d", length);
- memcpy((g_mux_obj_ptr->info_field + frame_length),data, length);\r
- dbg("MEMCPY :DONE");
- frame_length += length;\r
- }
- else {
+ if (length > 0) {
+ memcpy((g_mux_obj_ptr->info_field + frame_length), data, length);
+ frame_length += length;
+ } else {
dbg("info field length is zero");
}
/*5.2.1.6 Frame Checking Sequence Field (FCS)*/
- g_mux_obj_ptr->info_field[frame_length++] = calc_crc(g_mux_obj_ptr->info_field+1, crc_len);\r
+ g_mux_obj_ptr->info_field[frame_length++] = calc_crc(g_mux_obj_ptr->info_field + 1, crc_len);
/*Flag Octet*/
- g_mux_obj_ptr->info_field[frame_length++] = 0xF9;\r
+ g_mux_obj_ptr->info_field[frame_length++] = 0xF9;
- total_frame_length = frame_length;\r
- }
- else if (0x01 == g_mux_mode) { /* TBD MUX_MODE_ADVANCE */\r
- dbg("For PHASE 2 !!");
+ total_frame_length = frame_length;
+ } else if (0x01 == g_mux_mode) { /* TBD MUX_MODE_ADVANCE */
+ dbg("Advanced MUX mode : TBD");
}
- *out_data_len = total_frame_length;\r
+ *out_data_len = total_frame_length;
dbg("*out_data_len: %d", *out_data_len);
- dbg("Exit total_frame_length: %d", total_frame_length);\r
- return g_mux_obj_ptr->info_field;\r
+ dbg("Exit total_frame_length: %d", total_frame_length);
+ return g_mux_obj_ptr->info_field;
}
-static int rcv_crc_check(unsigned char *data, unsigned char len, unsigned char rcv_FCS)\r
+static int rcv_crc_check(unsigned char *data, unsigned char len, unsigned char rcv_FCS)
{
unsigned char FCS = 0xFF;
- dbg("Entry");\r
- /* 'len' is the number of bytes in the message, 'data' points to message */\r
+ /* 'len' is the number of bytes in the message, 'data' points to message */
while (len--) {
- FCS = crc_table[FCS ^ *data++];\r
+ FCS = crc_table[FCS ^ *data++];
}
-
+
/*Ones complement*/
- FCS = crc_table[FCS ^ rcv_FCS];\r
-
+ FCS = crc_table[FCS ^ rcv_FCS];
+
/* 0xCF is the reversed order of 11110011 */
- if (0xCF == FCS) { /* FCS is OK */
- dbg("Exit");\r
+ if (0xCF == FCS) { /* FCS is OK */
return 1;
- }
- else { /* FCS is NOT OK */
- err("Exit");\r
+ } else { /* FCS is NOT OK */
return 0;
}
}
-static void tcore_cmux_flush_channel_data(void)\r
+static void tcore_cmux_flush_channel_data(void)
{
dbg("Entry");
- g_mux_obj_ptr->info_field_len =0x0;\r
- memset(g_mux_obj_ptr->info_field, 0x0, MAX_CMUX_BUFFER_SIZE);\r
-
+ g_mux_obj_ptr->info_field_len = 0x0;
+ memset(g_mux_obj_ptr->info_field, 0x0, MAX_CMUX_BUFFER_SIZE);
+
dbg("Exit");
return;
}
-static void tcore_cmux_control_channel_handle(void)\r
+static void tcore_cmux_control_channel_handle(void)
{
- unsigned char cmd_type;\r
- int msg_len = 0;\r
- unsigned char *msg_start_ptr =NULL;\r
+ unsigned char cmd_type;
+ int msg_len = 0;
+ unsigned char *msg_start_ptr = NULL;
+
dbg("Entry");
-
+
/* 5.4.6.1 Message format
* All messages sent between the multiplexers conform to the following type, length, value format:
* Type Length Value 1 Value2 \85
*/
- if (g_mux_obj_ptr->info_field_len > 0) { \r
- msg_start_ptr = g_mux_obj_ptr->info_field;\r
- cmd_type = g_mux_obj_ptr->info_field[0];\r
- \r
- /* The EA bit is an extension bit. The EA bit is set to 1 in the last octet of the sequence;
+ if (g_mux_obj_ptr->info_field_len > 0) {
+ msg_start_ptr = g_mux_obj_ptr->info_field;
+ cmd_type = g_mux_obj_ptr->info_field[0];
+
+ /* The EA bit is an extension bit. The EA bit is set to 1 in the last octet of the sequence;
* in other octets EA is set to 0.
- *
+ *
* Search for the last octet
*/
- while( (*msg_start_ptr++ & 0x01)) { //TBD\r
- msg_len ++;\r
+ while ((*msg_start_ptr++ & 0x01)) { // TBD
+ msg_len++;
}
-
- if((cmd_type & 0x02) == 0x02) { //This is a command Request\r
- switch(cmd_type)\r
- {\r
- case CMUX_COMMAND_MSC:\r
- {\r
+
+ if ((cmd_type & 0x02) == 0x02) { // This is a command Request
+ switch (cmd_type) {
+ case CMUX_COMMAND_MSC:
+ {
dbg("Modem Status Command");
- break;\r
+ break;
}
- case CMUX_COMMAND_CLD:\r
- {\r
- dbg("Multiplexer close down");\r
+
+ case CMUX_COMMAND_CLD:
+ {
+ dbg("Multiplexer close down");
tcore_cmux_close();
- break;\r
+ break;
}
- default:\r
+
+ default:
{
- /* We will be supporting these commands in Phase 2 */\r
- dbg("Default");\r
- break;\r
+ /* We will be supporting these commands in Phase 2 */
+ dbg("Default");
+ break;
+ }
}
- }\r
}
- }
- else {
+ } else {
err("Frame length is less than ZERO");
}
return;
}
-static void tcore_cmux_process_channel_data(CHANNEL *channel_info_ptr)\r
+static void tcore_cmux_process_channel_data(CHANNEL *channel_info_ptr)
{
- int frame_type;\r
- int channel_id;\r
+ int frame_type;
+ int channel_id;
int len;
- unsigned char * send_data=NULL;
+ unsigned char *send_data = NULL;
static int count = 0;
-\r
- int ret;\r
+ int ret;
+
dbg("Entry");
- channel_id = channel_info_ptr->channel_id;\r
- dbg("Channel ID: %d", channel_id);\r
-
- frame_type = channel_info_ptr->frame_type & 0xEF;\r
- dbg("frame_type: 0x%x", frame_type);\r
+ channel_id = channel_info_ptr->channel_id;
+ dbg("Channel ID: %d", channel_id);
- switch(frame_type)\r
- {
- case CMUX_COMMAND_UI:\r
- case CMUX_COMMAND_UIH:\r
- {
- dbg("Received UI/UIH Frame");\r
- if(0 == channel_id) { /* This is control info */\r
- dbg("Control information");
- tcore_cmux_control_channel_handle();
- }
- else {
- dbg("Normal information");\r
- //put in the logical HAL queue
- //this goes to the Cobject
+ frame_type = channel_info_ptr->frame_type & 0xEF;
+ dbg("frame_type: 0x%x", frame_type);
- tcore_cmux_recv_mux_data(channel_info_ptr);\r
- }
- break;
+ switch (frame_type) {
+ case CMUX_COMMAND_UI:
+ case CMUX_COMMAND_UIH:
+ {
+ dbg("Received UI/UIH Frame");
+ if (0 == channel_id) { /* This is control info */
+ dbg("Control information");
+ tcore_cmux_control_channel_handle();
+ } else {
+ dbg("Normal information");
+ // put in the logical HAL queue, this goes to the Cobject
+ tcore_cmux_recv_mux_data(channel_info_ptr);
}
- case CMUX_COMMAND_UA:\r
- {
- dbg("Received UA Frame");
- dbg("channel_info_ptr->state: %d", channel_info_ptr->state);\r
- if(MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA == channel_info_ptr->state) {\r
- channel_info_ptr->state = MUX_CHANNEL_ESTABLISHED;\r
-
- count++;
- dbg("Count: %d", count);
- if(MAX_CMUX_CHANNELS_SUPPORTED == count) {\r
- /* Indicate to CoreObject */
- CoreObject *co = NULL;
-
- /* 'modem' Core Object */
- co = g_mux_obj_ptr->modem_co;\r
- if(NULL == co) {
- err("'modem' Core object is not present");
- return;
- }
+ break;
+ }
- /* Emit callback */
- dbg("Emit Core object callback");
- tcore_object_emit_callback(co, "CMUX-UP", NULL);
- dbg("Emitted Core object callback");
-\r
- /* Reset 'count' */\r
- count = 0;
+ case CMUX_COMMAND_UA:
+ {
+ dbg("Received UA Frame");
+ dbg("channel_info_ptr->state: %d", channel_info_ptr->state);
+ if (MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA == channel_info_ptr->state) {
+ channel_info_ptr->state = MUX_CHANNEL_ESTABLISHED;
+
+ count++;
+ dbg("Count: %d", count);
+ if (MAX_CMUX_CHANNELS_SUPPORTED == count) {
+ /* Indicate to CoreObject */
+ CoreObject *co = NULL;
+
+ /* 'modem' Core Object */
+ co = g_mux_obj_ptr->modem_co;
+ if (NULL == co) {
+ err("'modem' Core object is not present");
+ return;
}
- }
- else if(MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA == channel_info_ptr->state) {\r
- channel_info_ptr->state = MUX_CHANNEL_CLOSED;\r
- if(0 == channel_id) {\r
- g_mux_obj_ptr->state = MUX_CLOSED;\r
- tcore_cmux_close();
- }
+ /* Emit callback */
+ dbg("Emit Core object callback");
+ tcore_object_emit_callback(co, "CMUX-UP", NULL);
+ dbg("Emitted Core object callback");
+
+ /* Reset 'count' */
+ count = 0;
}
- else {
- err("Received UA in wrong state!!!");
+ } else if (MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA == channel_info_ptr->state) {
+ channel_info_ptr->state = MUX_CHANNEL_CLOSED;
+
+ if (0 == channel_id) {
+ g_mux_obj_ptr->state = MUX_CLOSED;
+ tcore_cmux_close();
}
- break;
+ } else {
+ err("Received UA in wrong state!!!");
}
- case CMUX_COMMAND_DM:\r
- {
- /* 5.4.1 DLC Establishment : If the responding station is not ready or unwilling
- * to establish the particular DLC it will reply with a DM frame with the
- * F-bit set to 1.
+ break;
+ }
+
+ case CMUX_COMMAND_DM:
+ {
+ /* 5.4.1 DLC Establishment : If the responding station is not ready or unwilling
+ * to establish the particular DLC it will reply with a DM frame with the
+ * F-bit set to 1.
+ */
+ dbg("Received DM Frame");
+ if ((MUX_CHANNEL_ESTABLISHED == channel_info_ptr->state)
+ || (MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA == channel_info_ptr->state)) {
+ /* Channel State set to Close */
+ channel_info_ptr->state = MUX_CHANNEL_CLOSED;
+ }
+
+ /* Flush the Channel data */
+ tcore_cmux_flush_channel_data();
+
+ break;
+ }
+
+ case CMUX_COMMAND_DISC:
+ {
+ dbg("Received DISC Frame");
+ if (0 == channel_info_ptr->poll_final_bit) {
+ /* In the case where a CMUX_COMMAND_SABM or CMUX_COMMAND_DISC command with
+ * the P bit set to 0 is received then the received frame shall be discarded.
*/
- dbg("Received DM Frame");
- if((MUX_CHANNEL_ESTABLISHED == channel_info_ptr->state)\r
- || (MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA == channel_info_ptr->state)) {\r
- /* Channel State set to Close */\r
- channel_info_ptr->state = MUX_CHANNEL_CLOSED;\r
+
+ /* Flush the Channel data */
+ tcore_cmux_flush_channel_data();
+ } else {
+ if (MUX_CHANNEL_CLOSED == channel_info_ptr->state) {
+ /* If a CMUX_COMMAND_DISC command is received while in disconnected mode
+ * a CMUX_COMMAND_DM response should be sent
+ */
+
+ /* Encoding frame */
+ send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_DM, 1, 1, 1, &len);
+ } else { // send Unnumbered Acknowledgement
+ send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_UA, 1, 1, 1, &len);
}
-\r
- /* Flush the Channel data */\r
+
+ if (0 == len) {
+ err("Failed to encode");
+ return;
+ }
+
+ /* Send CMUX data */
+ ret = tcore_cmux_send_data(len, send_data);
+
+ /* Flush the Channel data */
tcore_cmux_flush_channel_data();
- break;
- }
- case CMUX_COMMAND_DISC:\r
- {
- dbg("Received DISC Frame");
- if(0 == channel_info_ptr->poll_final_bit) {\r
- /* In the case where a CMUX_COMMAND_SABM or CMUX_COMMAND_DISC command with\r
- * the P bit set to 0 is received then the received frame shall be discarded.\r
- */
-\r
- /* Flush the Channel data */\r
- tcore_cmux_flush_channel_data();
+ /* 5.3.4 Disconnect (DISC) command: CMUX_COMMAND_DISC command sent at DLCI 0
+ * have the same meaning as the Multiplexer Close Down command
+ */
+ if (0 == channel_id) {
+ g_mux_obj_ptr->state = MUX_CLOSED;
+
+ /* Close CMUX */
+ tcore_cmux_close();
}
- else {
- if(MUX_CHANNEL_CLOSED == channel_info_ptr->state) {\r
- /* If a CMUX_COMMAND_DISC command is received while in disconnected mode\r
- * a CMUX_COMMAND_DM response should be sent\r
- */\r
-\r
- /* Encoding frame */
- send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_DM, 1, 1, 1, &len);\r
- }
- else { //send Unnumbered Acknowledgement
- send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_UA, 1, 1, 1, &len);\r
- }
+ }
+ break;
+ }
- if(0 == len) {
- err("Failed to encode");
- return;
- }
-
- /* Send CMUX data */\r
- ret = tcore_cmux_send_data(len, send_data);\r
- \r
- /* Flush the Channel data */\r
- tcore_cmux_flush_channel_data();
-\r
- /* 5.3.4 Disconnect (DISC) command: CMUX_COMMAND_DISC command sent at DLCI 0\r
- * have the same meaning as the Multiplexer Close Down command\r
- */\r
- if(0 == channel_id) {\r
- g_mux_obj_ptr->state = MUX_CLOSED;\r
-\r
- /* Close CMUX */\r
- tcore_cmux_close();
- }
+ case CMUX_COMMAND_SABM:
+ {
+ dbg("Received SABM Frame");
+ if (0 == channel_info_ptr->poll_final_bit) {
+ /* In the case where a CMUX_COMMAND_SABM or CMUX_COMMAND_DISC command with
+ * the P bit set to 0 is received then the received frame shall be discarded.
+ */
+
+ /* Flush the Channel data */
+ tcore_cmux_flush_channel_data();
+ } else {
+ /* Encoding frame */
+ send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_UA, 1, 1, 1, &len);
+ if (0 != len) {
+ /* Send CMUX data */
+ ret = tcore_cmux_send_data(len, send_data);
+ } else {
+ err("Failed to encode");
}
- break;
- }
- case CMUX_COMMAND_SABM:\r
- {
- dbg("Received SABM Frame");
- if(0 == channel_info_ptr->poll_final_bit) {\r
- /* In the case where a CMUX_COMMAND_SABM or CMUX_COMMAND_DISC command with\r
- * the P bit set to 0 is received then the received frame shall be discarded.\r
- */\r
-\r
- /* Flush the Channel data */\r
- tcore_cmux_flush_channel_data();
+
+ if (channel_info_ptr->state != MUX_CHANNEL_ESTABLISHED) {
+ /* Channel State set to Established */
+ channel_info_ptr->state = MUX_CHANNEL_ESTABLISHED;
}
- else {
- /* Encoding frame */\r
- send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_UA, 1, 1, 1, &len); \r
- if(0 != len) {\r
- /* Send CMUX data */\r
- ret = tcore_cmux_send_data(len,send_data);\r
- }\r
- else {\r
- err("Failed to encode");\r
- }\r
-
- if(channel_info_ptr->state != MUX_CHANNEL_ESTABLISHED) {\r
- /* Channel State set to Established */\r
- channel_info_ptr->state = MUX_CHANNEL_ESTABLISHED;\r
- }
- }
- break;
}
+ break;
+ }
}
- dbg("Exit");\r
- return ;
+ dbg("Exit");
+ return;
}
-static void tcore_cmux_process_rcv_frame( unsigned char *data, int len)
+static void tcore_cmux_process_rcv_frame(unsigned char *data, int len)
{
- unsigned char *frame_process_ptr = data;\r
- unsigned char *buf_start_ptr = data;\r
+ unsigned char *frame_process_ptr = data;
+ unsigned char *buf_start_ptr = data;
+
+ CHANNEL *ch = NULL;
+ unsigned char channel_id;
+ int header_length;
- CHANNEL *ch =NULL;
- unsigned char channel_id;\r
- int header_length;\r
dbg("Entry");
tcore_cmux_flush_channel_data();
-\r
-#if 1\r
- //testing\r
- dbg("len: %d ", len);\r
- {\r
- int i=0;\r
- for(i = 0; i < len ; i++) {\r
- dbg("%02x", data[i]);\r
- }\r
- }\r
-#endif\r
/* Get the Channel ID : 1st byte will be flag (F9)..Flag checking is already done.*/
- channel_id = (*++frame_process_ptr >> 2) & 0x3F;\r
+ channel_id = (*++frame_process_ptr >> 2) & 0x3F;
- if(channel_id < MAX_CMUX_CHANNELS_SUPPORTED) { //max channel is 8\r
- ch = g_mux_obj_ptr->channel_info[channel_id];\r
+ if (channel_id < MAX_CMUX_CHANNELS_SUPPORTED) { // max channel is 8
+ ch = g_mux_obj_ptr->channel_info[channel_id];
- ch->channel_id = channel_id;\r
+ ch->channel_id = channel_id;
- //get the EA bit
- ch->ext_bit = *frame_process_ptr & 0x01;\r
+ // get the EA bit
+ ch->ext_bit = *frame_process_ptr & 0x01;
- //get the CR bit
- ch->cr_bit = (*frame_process_ptr++ >> 1) & 0x01;\r
+ // get the CR bit
+ ch->cr_bit = (*frame_process_ptr++ >> 1) & 0x01;
- //get the Frame Type
- ch->frame_type = *frame_process_ptr++;\r
+ // get the Frame Type
+ ch->frame_type = *frame_process_ptr++;
- //get the poll/Final bit
- ch->poll_final_bit = (ch->frame_type & 0x10) >> 4;\r
+ // get the poll/Final bit
+ ch->poll_final_bit = (ch->frame_type & 0x10) >> 4;
- //get the length . TBD
- if(*frame_process_ptr & 0x01) { //if, len < 127\r
- g_mux_obj_ptr->info_field_len = *frame_process_ptr++ >> 1;\r
- header_length = 3;\r
+ // get the length . TBD
+ if (*frame_process_ptr & 0x01) { // if, len < 127
+ g_mux_obj_ptr->info_field_len = *frame_process_ptr++ >> 1;
+ header_length = 3;
+ } else {
+ 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;
+ frame_process_ptr++;
}
- else {
- g_mux_obj_ptr->info_field_len = *(frame_process_ptr + 1) << 7;\r
- g_mux_obj_ptr->info_field_len = g_mux_obj_ptr->info_field_len | ((*frame_process_ptr++ & 0xFE) >> 1);\r
- header_length = 4;\r
- frame_process_ptr++;\r
- }
- dbg("info_field_len: %d", g_mux_obj_ptr->info_field_len);\r
-
+ dbg("info_field_len: %d", g_mux_obj_ptr->info_field_len);
+
/* Copy received information field */
- memcpy(g_mux_obj_ptr->info_field, frame_process_ptr, g_mux_obj_ptr->info_field_len);\r
-\r
- frame_process_ptr = frame_process_ptr + g_mux_obj_ptr->info_field_len;\r
+ memcpy(g_mux_obj_ptr->info_field, frame_process_ptr, g_mux_obj_ptr->info_field_len);
- //CRC check of the header
- if (rcv_crc_check(buf_start_ptr+1, header_length, *frame_process_ptr)) {\r
+ frame_process_ptr = frame_process_ptr + g_mux_obj_ptr->info_field_len;
+
+ // CRC check of the header
+ if (rcv_crc_check(buf_start_ptr + 1, header_length, *frame_process_ptr)) {
dbg("Calling tcore_cmux_process_channel_data");
tcore_cmux_process_channel_data(ch);
- }
- else {
+ } else {
err("CRC check of the header FAILED.. Drop the packet !!");
}
- }
- else {
+ } else {
err("Incorrect channel... Drop the packet !!");
}
return;
}
-int tcore_cmux_rcv_from_hal(unsigned char *data, int len)
+int tcore_cmux_rcv_from_hal(unsigned char *data, size_t length)
{
- unsigned char *buf =data;
- int count =0;\r
- int i = 0;\r
- int actual_len = 0; //actual length\r
-
- unsigned char *mux_temp_buffer = g_mux_obj_ptr->mux_temp_buffer;\r
- unsigned char *mux_main_buffer = g_mux_obj_ptr->mux_main_buffer;\r
-
- int total_length = 0; /* Total length */\r
- int header_length = 0; /* Header length */\r
- int current_frame_length = 0; /* Current Frame length */ \r
- int pending_length = 0; /* pending length in array */ \r
- dbg("Entry");
+ #define TCORE_MUX_DECODE_FLAG_HUNT 0
+ #define TCORE_MUX_DECODE_ADDR_HUNT 1
+ #define TCORE_MUX_DECODE_CONTROL_HUNT 2
+ #define TCORE_MUX_DECODE_LENGTH1_HUNT 3
+ #define TCORE_MUX_DECODE_LENGTH2_HUNT 4
+ #define TCORE_MUX_DECODE_DATA_HUNT 5
+ #define TCORE_MUX_DECODE_FCS_HUNT 6
+
+ static int decode_state = TCORE_MUX_DECODE_FLAG_HUNT;
+ static unsigned char dec_fcs = 0xff;
+ static unsigned char mux_buffer[4096];
+ static unsigned char* dec_data = mux_buffer;
+ static unsigned short dec_length = 0;
+ static size_t full_frame_len = 0;
+
+ size_t pos = -1;
+ int cp_len = 0;
+
+DECODE_STATE_CHANGE:
+ if (++pos >= length)
+ {
+ return 1;
+ }
- if (len > MAX_CMUX_BUFFER_SIZE){
- err("len - %d is more than MAX limit !!" ,len);
- return 0;
+ switch(decode_state)
+ {
+ case TCORE_MUX_DECODE_FLAG_HUNT: full_frame_len = 0; dec_length = 0; dec_fcs = 0xff; dec_data = mux_buffer; goto FLAG_HUNT; break;
+ case TCORE_MUX_DECODE_ADDR_HUNT: goto ADDR_HUNT; break;
+ case TCORE_MUX_DECODE_CONTROL_HUNT: goto CONTROL_HUNT; break;
+ case TCORE_MUX_DECODE_LENGTH1_HUNT: goto LENGTH1_HUNT; break;
+ case TCORE_MUX_DECODE_LENGTH2_HUNT: goto LENGTH2_HUNT; break;
+ case TCORE_MUX_DECODE_DATA_HUNT: goto DATA_HUNT; break;
+ case TCORE_MUX_DECODE_FCS_HUNT: goto FCS_HUNT; break;
+ }
+
+FLAG_HUNT:
+ while (data[pos] != 0xF9) {
+ if (++pos >= length) {
+ return 1;
}
-
- if( (len > 0 ) && (data != NULL)) {
- if(g_mux_obj_ptr->is_waiting) {\r
- /* Checking if Frame fully contains F9 or not. If only F9, then reject, esle process */\r
- while(*buf++ == 0xF9) {
- count++;
- }
+ }
+ decode_state = TCORE_MUX_DECODE_ADDR_HUNT;
+ goto DECODE_STATE_CHANGE;
- if (count == len) { // In case all are F9
- err("Not a valid frame");
- return 0;
- }
+ADDR_HUNT:
+ while (data[pos] == 0xF9) {
+ if (++pos >= length) {
+ return 1;
+ }
+ }
- dbg("cur_main_buf_len: %d len = %d", g_mux_obj_ptr->cur_main_buf_len, len);\r
- memcpy((mux_main_buffer + g_mux_obj_ptr->cur_main_buf_len), data, len);\r
-\r
- g_mux_obj_ptr->cur_main_buf_len = g_mux_obj_ptr->cur_main_buf_len + len;\r
- dbg("cur_main_buf_len: %d", g_mux_obj_ptr->cur_main_buf_len);\r
-\r
- if(g_mux_obj_ptr->msg_len <= len) {\r
- g_mux_obj_ptr->is_waiting = 0;\r
- tcore_cmux_rcv_from_hal(mux_main_buffer, g_mux_obj_ptr->cur_main_buf_len);\r
- }
- else {
- g_mux_obj_ptr->msg_len = g_mux_obj_ptr->msg_len - len;\r
- dbg("Still waiting for the complete frame!!!");
- }
+ dec_fcs = crc_table[dec_fcs^data[pos]];
+ decode_state = TCORE_MUX_DECODE_CONTROL_HUNT;
+ *dec_data++ = 0xF9;
+ *dec_data++ = data[pos];
+ full_frame_len += 2;
+ goto DECODE_STATE_CHANGE;
+
+CONTROL_HUNT:
+ dec_fcs = crc_table[dec_fcs^data[pos]];
+ decode_state = TCORE_MUX_DECODE_LENGTH1_HUNT;
+ *dec_data++ = data[pos];
+ full_frame_len++;
+ goto DECODE_STATE_CHANGE;
+
+LENGTH1_HUNT:
+ dec_length = data[pos] >> 1;
+ dec_fcs = crc_table[dec_fcs^data[pos]];
+ if (data[pos] & 0x1)
+ { // ea
+ if (dec_length > 0)
+ {
+ decode_state = TCORE_MUX_DECODE_DATA_HUNT;
}
- else {
- if(*buf ==0xF9) { // start flag present
- /* Remove extra flags */\r
- while(*++buf == 0xF9) {
- count++;
- }
+ else
+ {
+ decode_state = TCORE_MUX_DECODE_FCS_HUNT;
+ }
+ }
+ else
+ {
+ decode_state = TCORE_MUX_DECODE_LENGTH2_HUNT;
+ }
- /* Check if received data has atleast three octets between flags */\r
- for(i = 0; ( (i<3) && (*(buf+i)!=0xF9)); i++);
+ *dec_data++ = data[pos];
+ full_frame_len++;
+ goto DECODE_STATE_CHANGE;
- if((i<3) || (count == (len-1))) { // In case all are F9 or three octets between flags not found\r
- err("Not a valid frame");
- return 0;
- }
+LENGTH2_HUNT:
+ dec_length |= ((unsigned short)data[pos] << 7);
+ dec_fcs = crc_table[dec_fcs^data[pos]];
+ decode_state = TCORE_MUX_DECODE_DATA_HUNT;
+ *dec_data++ = data[pos];
+ full_frame_len++;
+ goto DECODE_STATE_CHANGE;
- actual_len = len - count;\r
- dbg("actual_length: %d", actual_len);\r
-
- /* Memset mux_temp_buffer */\r
- memset(mux_temp_buffer, 0x0, MAX_CMUX_BUFFER_SIZE);\r
-
- /* Copy data to mux_temp_buffer */ \r
- memcpy(mux_temp_buffer, data + count, actual_len);\r
-
- buf = mux_temp_buffer + 3;\r
-\r
- /* Find the info length field of the current frame */\r
- FIND_LENGTH(buf, header_length, total_length);\r
-\r
- /* Calculate the current frame length including the headers */\r
- current_frame_length = header_length + total_length;\r
-\r
- /* Memset mux_main_buffer */\r
- memset(mux_main_buffer, 0x0, MAX_CMUX_BUFFER_SIZE);\r
-\r
- if(current_frame_length == actual_len) { //Only 1 frame is received and its a complete frame\r
- dbg("Single frame received");\r
- if(mux_temp_buffer[current_frame_length-0x01] == 0xF9) {\r
- dbg("current_frame_length: %d", current_frame_length);\r
- \r
- /* Copy received frame to mux_main_buffer */\r
- memcpy(mux_main_buffer,mux_temp_buffer, current_frame_length);\r
-\r
- /* Process the recieved frame */\r
- tcore_cmux_process_rcv_frame(mux_main_buffer, current_frame_length);\r
- \r
- /* Initialize the main buffer */\r
- memset(mux_main_buffer, 0x0, MAX_CMUX_BUFFER_SIZE);\r
- }
- else {
- err("End flag missing!!!");
- return 0;
- }
- }
- else if(current_frame_length < actual_len) { //more than one frame\r
- dbg("Multiple frames received");\r
- if(mux_temp_buffer[current_frame_length-0x01] == 0xF9) {\r
- dbg("current_frame_length: %d", current_frame_length);\r
-
- /* Copy received frame to mux_main_buffer */\r
- memcpy(mux_main_buffer, mux_temp_buffer, current_frame_length);\r
-
- /* Process the recieved frame */\r
- tcore_cmux_process_rcv_frame(mux_main_buffer ,current_frame_length);\r
-\r
- /* Initialize the main buffer */\r
- memset(mux_main_buffer, 0x0, MAX_CMUX_BUFFER_SIZE);\r
- mux_main_buffer[0] = 0xF9;\r
- \r
- pending_length = actual_len - current_frame_length;\r
- dbg("pending_length: %d", pending_length);\r
-\r
- /* Copy the rest of the frames to mux_main_buffer */\r
- memcpy((mux_main_buffer + 0x01), (mux_temp_buffer + current_frame_length), pending_length);\r
-\r
- /* Receive pending frames */\r
- tcore_cmux_rcv_from_hal(mux_main_buffer, pending_length + 0x01);\r
- }
- else {
- err("End flag missing!!!");
- return 0;
- }
- }
- else if(current_frame_length > actual_len) { // frame is incomplete. Yet to receive the full frame\r
- dbg("Incomplete frame received");\r
- g_mux_obj_ptr->is_waiting = 1; \r
- dbg("actual_len: %d", actual_len);\r
-\r
- /* Copy received frame to mux_main_buffer */\r
- memcpy(mux_main_buffer, mux_temp_buffer + count, actual_len);\r
- \r
- g_mux_obj_ptr->msg_len = current_frame_length - actual_len;\r
- g_mux_obj_ptr->cur_main_buf_len = actual_len;\r
- }
- }
- else {
- err("Start flag missing!!!");
- }
- }
- }
- else {
- err("Incorrect Length!!! or NULL Data!!");
+DATA_HUNT:
+ if (dec_length < (length - pos)) // frame data fully available in the buffer
+ {
+ cp_len = dec_length;
+ decode_state = TCORE_MUX_DECODE_FCS_HUNT;
+ }
+ else // frame data partially available in the buffer
+ {
+ cp_len = (length - pos);
+ decode_state = TCORE_MUX_DECODE_DATA_HUNT;
}
- dbg("Exit");
- return 1;
+ memcpy(dec_data, data + pos, cp_len);
+ dec_data += cp_len;
+ pos += (cp_len - 1);
+ dec_length -= cp_len;
+ full_frame_len += cp_len;
+
+ goto DECODE_STATE_CHANGE;
+
+FCS_HUNT:
+ //if (crc_table[dec_fcs^data[pos]] == 0xCF) // valid FCS, store frame.
+ {
+ *dec_data++ = data[pos];
+ *dec_data++ = 0xF9;
+ full_frame_len += 2;
+ tcore_cmux_process_rcv_frame(mux_buffer, full_frame_len);
+ }
+
+ // enter flag hunt mode
+ decode_state = TCORE_MUX_DECODE_FLAG_HUNT;
+ goto DECODE_STATE_CHANGE;
}
-static void tcore_cmux_channel_init(CMUX_Channels channel_id)\r
+static void tcore_cmux_channel_init(CMUX_Channels channel_id)
{
CHANNEL *ch = NULL;
- dbg("Entry");
-
- ch = g_mux_obj_ptr->channel_info[channel_id];\r
+
+ ch = g_mux_obj_ptr->channel_info[channel_id];
memset(ch, 0x0, sizeof(CHANNEL));
-
- ch->channel_id = channel_id;\r
+
+ ch->channel_id = channel_id;
ch->state = MUX_CHANNEL_SABM_SEND_WAITING_FOR_UA;
ch->co = NULL;
ch->hal = NULL;
/* TODO - Check if required */
- ch->frame_type = CMUX_COMMAND_SABM;\r
- ch->ext_bit = 0x01;\r
- ch->cr_bit = 0x01;\r
- ch->poll_final_bit = 0x01;\r
+ ch->frame_type = CMUX_COMMAND_SABM;
+ ch->ext_bit = 0x01;
+ ch->cr_bit = 0x01;
+ ch->poll_final_bit = 0x01;
dbg("Channel ID %d initialized", channel_id);
-
- dbg("Exit");
+
return;
}
-static void tcore_cmux_close_channel(int channel_id)\r
+static void tcore_cmux_close_channel(int channel_id)
{
CHANNEL *ch = NULL;
unsigned char *send_data = NULL;
- int ret, len =0;\r
+ int ret, len = 0;
+
dbg("Entry");
- ch = g_mux_obj_ptr->channel_info[channel_id];\r
-
- if(ch->state != MUX_CHANNEL_CLOSED) {
- ch->frame_type = CMUX_COMMAND_DISC;\r
- ch->ext_bit = 0x01;\r
- ch->cr_bit = 0x01;\r
+ ch = g_mux_obj_ptr->channel_info[channel_id];
+
+ if (ch->state != MUX_CHANNEL_CLOSED) {
+ ch->frame_type = CMUX_COMMAND_DISC;
+ ch->ext_bit = 0x01;
+ ch->cr_bit = 0x01;
ch->state = MUX_CHANNEL_DISC_SEND_WAITING_FOR_UA;
/* Send DSC command */
- /* Encoding frame */\r
- send_data = tcore_encode_cmux_frame(NULL,0, channel_id, CMUX_COMMAND_DISC, 0x01, 0x01, 0x01, &len); \r
- if(0 != len) {\r
- /* Send CMUX data */\r
- ret = tcore_cmux_send_data(len, send_data);\r
- }\r
- else {\r
- err("Failed to encode");\r
- }\r
- }
- else {
+ /* Encoding frame */
+ send_data = tcore_encode_cmux_frame(NULL, 0, channel_id, CMUX_COMMAND_DISC, 0x01, 0x01, 0x01, &len);
+ if (0 != len) {
+ /* Send CMUX data */
+ ret = tcore_cmux_send_data(len, send_data);
+ } else {
+ err("Failed to encode");
+ }
+ } else {
/* Channel is already closed */
err("Channel is already closed");
}
dbg("Exit");
- return;\r
+ return;
}
-static void tcore_cmux_free(void)\r
+static void tcore_cmux_free(void)
{
int channel;
+
dbg("Entry");
-
- if(g_mux_obj_ptr) {\r
+
+ if (g_mux_obj_ptr) {
/* Free Information Field */
- if (g_mux_obj_ptr->info_field) \r
- free(g_mux_obj_ptr->info_field);\r
-
- for (channel = 0 ; channel < MAX_CMUX_CHANNELS_SUPPORTED ; channel++) {\r
+ if (g_mux_obj_ptr->info_field) {
+ free(g_mux_obj_ptr->info_field);
+ g_mux_obj_ptr->info_field = NULL;
+ }
+
+ for (channel = 0; channel < MAX_CMUX_CHANNELS_SUPPORTED; channel++) {
/* Free Channel Information */
- if(g_mux_obj_ptr->channel_info[channel]) {\r
- free(g_mux_obj_ptr->channel_info[channel]);\r
+ if (g_mux_obj_ptr->channel_info[channel]) {
+ free(g_mux_obj_ptr->channel_info[channel]);
+ g_mux_obj_ptr->channel_info[channel] = NULL;
}
}
/* Free MUX Object */
- free(g_mux_obj_ptr);\r
- }
- else {
+ free(g_mux_obj_ptr);
+ g_mux_obj_ptr = NULL;
+ } else {
err("MUX Object doesn't exist");
}
return;
}
-TReturn tcore_cmux_init(TcorePlugin *plugin, TcoreHal *hal)\r
+TReturn tcore_cmux_init(TcorePlugin *plugin, TcoreHal *hal)
{
unsigned char *data = NULL;
int data_len = 0;
int index;
-\r
- TReturn ret = TCORE_RETURN_SUCCESS;\r
+
+ TReturn ret = TCORE_RETURN_SUCCESS;
+
dbg("Entry");
- dbg("Physical HAL: %x", hal);\r
+ dbg("Physical HAL: %x", hal);
/* Creat new CMUX Object */
- g_mux_obj_ptr = tcore_cmux_new();\r
- if(NULL == g_mux_obj_ptr) {\r
+ g_mux_obj_ptr = tcore_cmux_new();
+ if (NULL == g_mux_obj_ptr) {
err("Failed to create MUX object");
-\r
- ret = TCORE_RETURN_FAILURE;\r
- goto ERROR;\r
+
+ ret = TCORE_RETURN_FAILURE;
+ goto ERROR;
}
/* Save Plugin */
- g_mux_obj_ptr->plugin = plugin;\r
-
+ g_mux_obj_ptr->plugin = plugin;
+
/* Save Physical HAL */
- g_mux_obj_ptr->phy_hal = hal;\r
+ g_mux_obj_ptr->phy_hal = hal;
/* Setting Receive callback function for data received from Physical HAL */
- g_mux_obj_ptr->cb_func= tcore_cmux_recv_mux_data;\r
-
- /* After MUX setup, AT parse functionality of PHY HAL should be disabled,
- * here we change the mode of PHYSICAL HAL to Transparent.\r
- */
- tcore_hal_set_mode(g_mux_obj_ptr->phy_hal, TCORE_HAL_MODE_TRANSPARENT);\r
+ g_mux_obj_ptr->cb_func = tcore_cmux_recv_mux_data;
+
+ /* After MUX setup, AT parse functionality of PHY HAL should be disabled,
+ * here we change the mode of PHYSICAL HAL to Transparent.
+ */
+ tcore_hal_set_mode(g_mux_obj_ptr->phy_hal, TCORE_HAL_MODE_TRANSPARENT);
dbg("Physical HAL mode changed to Transparent");
-
+
/* Initialize all the Channels */
/* Open all Channels */
- for(index = 0 ; index < MAX_CMUX_CHANNELS_SUPPORTED ; index++) {\r
+ for (index = 0; index < MAX_CMUX_CHANNELS_SUPPORTED; index++) {
+ dbg("Initialize the Channel %d", index);
+ tcore_cmux_channel_init((CMUX_Channels) index);
- dbg("Initialize the Channel %d", index);
- tcore_cmux_channel_init((CMUX_Channels)index);
-
dbg("Opening Channel %d", index);
/* Encode CMUX Frame */
- data = tcore_encode_cmux_frame(NULL, 0, index, CMUX_COMMAND_SABM, 0x01, 0x01, 0x01, &data_len);\r
- if(0 == data_len) {\r
+ data = tcore_encode_cmux_frame(NULL, 0, index, CMUX_COMMAND_SABM, 0x01, 0x01, 0x01, &data_len);
+ if (0 == data_len) {
err("Failed to encode");
-\r
- ret = TCORE_RETURN_FAILURE;\r
- goto ERROR;\r
+
+ ret = TCORE_RETURN_FAILURE;
+ goto ERROR;
}
dbg("data_len: %d data: %s", data_len, data);
- /* Send CMUX data */\r
- tcore_cmux_send_data(data_len, data);\r
+ /* Send CMUX data */
+ tcore_cmux_send_data(data_len, data);
dbg("CMUX Control Request sent to CP");
/* Set Core object and HAL */
- tcore_cmux_link_core_object_hal((CMUX_Channels)index, plugin);
+ tcore_cmux_link_core_object_hal((CMUX_Channels) index, plugin);
}
dbg("Exit");
- return ret;\r
+ return ret;
-ERROR:\r
- /* Free the allocated CMUX memory */\r
- tcore_cmux_free();\r
+ERROR:
+ /* Free the allocated CMUX memory */
+ tcore_cmux_free();
- err("Exit");\r
- return ret;\r
-}\r
+ err("Exit");
+ return ret;
+}
-void tcore_cmux_close(void)\r
+void tcore_cmux_close(void)
{
int channel = 0;
int index = 0;
CoreObject *co = NULL;
GSList *co_list = NULL;
+
dbg("Entry");
- for (channel = 0 ; channel < MAX_CMUX_CHANNELS_SUPPORTED ; channel++) {\r
+ for (channel = 0; channel < MAX_CMUX_CHANNELS_SUPPORTED; channel++) {
dbg("Channel ID: %d", channel);
index = 0;
tcore_cmux_close_channel(channel);
/* Revert Physical HAL as HAL of each Core Object associated to this Channel */
- while (NULL != cmux_channel_core_object[channel].core_object_name[index]) {\r
+ while (NULL != cmux_channel_core_object[channel].core_object_name[index]) {
co = NULL;
/* Core Objects list */
- co_list = g_mux_obj_ptr->channel_info[channel]->co;\r
+ co_list = g_mux_obj_ptr->channel_info[channel]->co;
dbg("Core Objects list : %p", co_list);
-
+
/* Core Object list may contain multiple Core Objects.
* Revert to Physical HAL for each of the Core Objects associated
* with this Channel
*/
- while(NULL != co_list) {
- if(NULL != co_list->data) {
- if(!strcmp((const char *)cmux_channel_core_object[channel].core_object_name[index], (const char *)tcore_object_ref_name((CoreObject *)co_list->data))) {\r
- co = (CoreObject *)co_list->data;
- dbg("Found the Core Object");
+ while (NULL != co_list) {
+ if (NULL != co_list->data) {
+ if (!strcmp((const char *) cmux_channel_core_object[channel].core_object_name[index], (const char *) tcore_object_ref_name((CoreObject *) co_list->data))) {
+ co = (CoreObject *) co_list->data;
+ dbg("Core Object found ");
break;
}
}
}
/* Set the previous Physical HAL as HAL for Core Object */
- if(NULL != co) {
- tcore_object_set_hal(co, g_mux_obj_ptr->phy_hal);\r
- }
- else {
+ if (NULL != co) {
+ tcore_object_set_hal(co, g_mux_obj_ptr->phy_hal);
+ } else {
/* Proceed to next Channel */
err("No more Core Objects present in this Channel");
break;
/* To next Core Object */
index++;
}
-
+
/* Free Logical HAL for Channel */
- tcore_hal_free(g_mux_obj_ptr->channel_info[channel]->hal);\r
+ tcore_hal_free(g_mux_obj_ptr->channel_info[channel]->hal);
+ g_mux_obj_ptr->channel_info[channel]->hal = NULL;
}
-
+
/* Change the mode of PHYSICAL HAL to Custom */
- tcore_hal_set_mode(g_mux_obj_ptr->phy_hal, TCORE_HAL_MODE_CUSTOM);\r
+ tcore_hal_set_mode(g_mux_obj_ptr->phy_hal, TCORE_HAL_MODE_AT);
/* Free all the allocated memory */
tcore_cmux_free();
-
+
dbg("Exit");
return;
}