bal packet indication bug fix, heartbeat and reboot procedures

Change-Id: If798c1802c488dd6b4a73595c72245b7d5daa8d7
diff --git a/device_simulator/bal_stub.c b/device_simulator/bal_stub.c
index 522c56a..78b4823 100644
--- a/device_simulator/bal_stub.c
+++ b/device_simulator/bal_stub.c
@@ -31,7 +31,7 @@
 
 char *voltha_ip_and_port = NULL;
 
-void *stub_thread(void *v) 
+void *stub_thread(void *v)
 {
    int status;
    pthread_mutex_lock(&lock);
@@ -65,7 +65,7 @@
                bal_access_terminal_key__init(&accTermKey);
                accTermKey.has_access_term_id = 1;
                accTermKey.access_term_id = 1;
-               
+
                BalAccessTerminalIndData data;
                memset(&data, 0, sizeof(BalAccessTerminalIndData));
                bal_access_terminal_ind_data__init(&data);
@@ -205,11 +205,12 @@
                BalPacketItuOmciChannelRx balomciresp;
                memset(&balomciresp, 0, sizeof(BalPacketItuOmciChannelRx));
                bal_packet_itu_omci_channel_rx__init(&balomciresp);
-                                              
+
                BalPacketKey balomcirespkey;
                memset(&balomcirespkey, 0, sizeof(BalPacketKey));
-               bal_packet_key__init(&balomcirespkey); 
+               bal_packet_key__init(&balomcirespkey);
                balomciresp.key = &balomcirespkey;
+               balIndCfg.balomciresp = &balomciresp;
 
                BalDest balomcirespkeydest;
                memset(&balomcirespkeydest, 0, sizeof(BalDest));
@@ -245,14 +246,14 @@
    return NULL;
 }
 
-void create_stub_thread() 
+void create_stub_thread()
 {
    pthread_t threadId = 0;
 
    /* create shared queue */
    shared_queue = createQueue();
 
-   pthread_create(&threadId, NULL, stub_thread, NULL);      
+   pthread_create(&threadId, NULL, stub_thread, NULL);
 
 }
 
@@ -276,7 +277,7 @@
       memcpy(temp->device_id, device_id, strlen(device_id));
    }
    temp->next = NULL;
-   return temp; 
+   return temp;
 }
 
 /* The function to add data to shared_queue - Add end of the queue */
@@ -320,7 +321,45 @@
 
 void stub_bal_init(BalInit *bal_init)
 {
-    client = grpc_c_client_init(bal_init->voltha_adapter_ip_port, "bal_client", NULL);
+    char *ip_and_port = NULL;
+    ip_and_port = bal_init->voltha_adapter_ip_port;
+    client = grpc_c_client_init(ip_and_port, "bal_client", NULL);
+}
+
+void stub_bal_stats_get(BalInterfaceStatData *statData)
+{
+    printf("Bal Stub - Get Stats In BalStubs : Got all the statistics\n");
+    statData->has_rx_bytes = 1;
+    statData->has_rx_packets=1;
+    statData->has_rx_ucast_packets=1;
+    statData->has_rx_mcast_packets=1;
+    statData->has_rx_bcast_packets=1;
+    statData->has_rx_error_packets=1;
+    statData->has_rx_unknown_protos=1;
+    statData->has_tx_bytes = 1;
+    statData->has_tx_packets=1;
+    statData->has_tx_ucast_packets=1;
+    statData->has_tx_mcast_packets=1;
+    statData->has_tx_bcast_packets=1;
+    statData->has_tx_error_packets=1;
+    statData->has_rx_crc_errors=1;
+    statData->has_bip_errors=1;
+
+    statData->rx_bytes = 1000;          /**< RFC 2233 */
+    statData->rx_packets = 100;        /**< RFC 1213 ucast + none-ucast */
+    statData->rx_ucast_packets = 5;  /**< RFC 2233 */
+    statData->rx_mcast_packets = 10;  /**< RFC 2233 */
+    statData->rx_bcast_packets = 15;  /**< RFC 2233 */
+    statData->rx_error_packets = 20;  /**< RFC 1213 */
+    statData->rx_unknown_protos = 45; /**< RFC 1213 */
+    statData->tx_bytes = 2000;          /**< RFC 2233 */
+    statData->tx_packets = 190;        /**< RFC 1213 ucast + none-ucast */
+    statData->tx_ucast_packets = 30;  /**< RFC 2233 */
+    statData->tx_mcast_packets = 50;  /**< RFC 2233 */
+    statData->tx_bcast_packets = 80;  /**< RFC 2233 */
+    statData->tx_error_packets = 40;  /**< RFC 1213 */
+    statData->rx_crc_errors = 5;     /**< Received packets with CRC error. */
+    statData->bip_errors = 15;
 }
 
 #endif
diff --git a/device_simulator/voltha_bal_driver.c b/device_simulator/voltha_bal_driver.c
index d919ba3..afdb73e 100755
--- a/device_simulator/voltha_bal_driver.c
+++ b/device_simulator/voltha_bal_driver.c
@@ -31,17 +31,175 @@
 #include "asfvolt16_driver.h"
 #endif
 
+#include <unistd.h>
+#include <sys/reboot.h>
+
 /* Global varibles */
 balCoreIpInfo coreIpPortInfo;
 
 static grpc_c_server_t *test_server;
 
-static void sigint_handler (int x) { 
+static void sigint_handler (int x) {
    grpc_c_server_destroy(test_server);
    exit(0);
 }
 
 /*
+ * This functions gets invoked whenever bal Heartbeat RPC gets called
+ */
+void bal__bal_api_heartbeat_cb(grpc_c_context_t *context)
+{
+   BalHeartbeat *bal_hb;
+   BalErr bal_err;
+
+   /*
+    * Read incoming message into set_cfg
+    */
+   printf("\nRecevied HeartBeat from Adapter\n");
+   if (context->gcc_payload) {
+	context->gcc_stream->read(context, (void **)&bal_hb, 0);
+   }
+
+   printf("Received Heart Beat msg\n");
+
+   bal_err__init(&bal_err);
+
+   bal_err.err= 0;
+
+   /*
+    * Write reply back to the client
+    */
+    if (!context->gcc_stream->write(context, &bal_err, 0)) {
+    } else {
+              printf("Failed to write\n");
+	      exit(1);
+    }
+
+    grpc_c_status_t status;
+    status.gcs_code = 0;
+
+    /*
+     * Finish response for RPC
+     */
+    if (context->gcc_stream->finish(context, &status)) {
+	printf("Failed to write status\n");
+	exit(1);
+    }
+
+    sleep(1);
+    printf("\nSent HeartBeat Response to Adapter\n");
+}
+
+/*
+ * This functions gets invoked whenever Bal reboot gets called
+ */
+void bal__bal_api_reboot_cb(grpc_c_context_t *context)
+{
+   BalReboot *read_device;
+   BalErr bal_err;
+   /*
+    * Read incoming message into get_cfg
+    */
+    if (context->gcc_payload) {
+       context->gcc_stream->read(context, (void **)&read_device, 0);
+    }
+
+   printf("Bal Server - Reboot : ======Entering Function Reboot ==============================\n");
+   printf("Bal Server - Reboot : Device ID is %s\n",read_device->device_id);
+
+   sync();
+   reboot(RB_AUTOBOOT);
+
+   /* system("init 6"); */
+   /*
+    * send it to BAL
+    */
+
+   bal_err__init(&bal_err);
+
+   bal_err.err= 0;
+
+   /*
+    * Write reply back to the client
+    */
+   if (!context->gcc_stream->write(context, &bal_err, 0)) {
+   } else {
+      printf("Bal Server - Reboot Failed to write\n");
+      exit(1);
+   }
+
+   grpc_c_status_t status;
+   status.gcs_code = 0;
+
+    /*
+    * Finish response for RPC
+    */
+    if (context->gcc_stream->finish(context, &status)) {
+        printf("Failed to write status\n");
+        exit(1);
+    }
+}
+
+/*
+ * This functions gets invoked whenever Bal Stats gets called
+ */
+void bal__bal_cfg_stat_get_cb(grpc_c_context_t *context)
+{
+    BalInterfaceKey *read_stats;
+
+    /*
+    * Read incoming message into get_cfg
+    */
+    if (context->gcc_payload) {
+       context->gcc_stream->read(context, (void **)&read_stats, 0);
+    }
+
+    printf("Bal Server - Get Stats :======Entering Function Get Stats ============\n");
+    printf("Bal Server - Get Stats :NNI port is %d\n",read_stats->intf_id);
+
+    BalInterfaceStat get_stats;
+    memset(&get_stats, 0, sizeof(BalInterfaceStat));
+    bal_interface_stat__init(&get_stats);
+
+    BalInterfaceStatData stat_data;
+    memset(&stat_data, 0, sizeof(BalInterfaceStatData));
+    bal_interface_stat_data__init(&stat_data);
+
+#ifndef BAL_STUB
+    /* Interface Type, Interface ID
+       stat_data - Statistics Data */
+    asfvolt16_bal_stats_get(read_stats->intf_type, read_stats->intf_id, &stat_data);
+    printf("Bal Server - Get Stats Not In BalStubs : Got all the statistics\n");
+#else
+    stub_bal_stats_get(&stat_data);
+    printf("Bal Server - Get Stats In BalStubs : Got all the statistics\n");
+#endif
+
+    get_stats.data = &stat_data;
+
+    if (!context->gcc_stream->write(context, &get_stats, 0)) {
+	   printf("Successfully Written Stats\n");
+    } else {
+       printf("Stats Failed to write\n");
+	   exit(1);
+    }
+
+    grpc_c_status_t status;
+    status.gcs_code = 0;
+
+    /*
+    * Finish response for RPC
+    */
+    if (context->gcc_stream->finish(context, &status)) {
+        printf("Failed to write status\n");
+        exit(1);
+    }
+
+    sleep(1);
+    printf("============ Returning from Stats Function============\n");
+}
+
+/*
  * This functions gets invoked whenever bal RPC gets called
  */
 void bal__bal_cfg_get_cb(grpc_c_context_t *context)
@@ -87,16 +245,17 @@
    /*
     * Write reply back to the client
     */
- 
+
    ret_val = context->gcc_stream->write(context, &bal_err, 0);
    if (ret_val != GRPC_C_WRITE_OK) {
       if(ret_val == GRPC_C_WRITE_PENDING) {
-         printf("write is pending, sleep for 10 sec: %d\n", ret_val);
+         printf("write is pending, sleep for 10 sec %d \n", ret_val);
          sleep(10);
       }
       else {
-         printf("Failed to write: %d\n", ret_val);
-         exit(1);
+         printf("Failed to write %d \n", ret_val);
+         printf("write is pending, sleep for 10 sec: %d\n", ret_val);
+         sleep(10);
       }
    }
 
@@ -114,8 +273,8 @@
 #ifdef BAL_STUB
    pthread_mutex_lock(&lock);
 
-   struct QNode *temp = newNode(set_cfg->hdr->obj_type, 
-         BAL_ERRNO__BAL_ERR_OK, 
+   struct QNode *temp = newNode(set_cfg->hdr->obj_type,
+         BAL_ERRNO__BAL_ERR_OK,
          set_cfg->device_id);
 
 /*   if(set_cfg->hdr->has_obj_type)
@@ -125,56 +284,63 @@
       {
          case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
             {
-               printf("\n***************************************************\n");  
+               printf("\n***************************************************\n");
                printf("Received Access Terminal Configuration msg\n");
-               printf("***************************************************\n");  
+               printf("***************************************************\n");
             }
             break;
          case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
             {
-               printf("\n***************************************************\n");  
+               printf("\n***************************************************\n");
                printf("Received PON Interface Configuration msg\n");
-               printf("***************************************************\n");  
+               printf("***************************************************\n");
                temp->intf_id = set_cfg->interface->key->intf_id;
                printf("Pon ID = %d\n", temp->intf_id);
             }
             break;
          case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
             {
-          printf("\n*****************************************************\n");  
+          printf("\n*****************************************************\n");
           printf("Received ONU Activation msg\n");
-          printf("*****************************************************\n");  
+          printf("*****************************************************\n");
           temp->intf_id = set_cfg->terminal->key->intf_id;
           temp->onu_id = set_cfg->terminal->key->sub_term_id;
           memset(temp->vendor_id, 0, BAL_DEVICE_STR_LEN);
-          memcpy(temp->vendor_id, 
-                set_cfg->terminal->data->serial_number->vendor_id, 
+          memcpy(temp->vendor_id,
+                set_cfg->terminal->data->serial_number->vendor_id,
                 strlen(set_cfg->terminal->data->serial_number->vendor_id));
           memset(temp->vendor_specific, 0, BAL_DEVICE_STR_LEN);
-          memcpy(temp->vendor_specific, 
-                set_cfg->terminal->data->serial_number->vendor_specific, 
+          memcpy(temp->vendor_specific,
+                set_cfg->terminal->data->serial_number->vendor_specific,
                 strlen(set_cfg->terminal->data->serial_number->vendor_specific));
 
             }
             break;
+         case BAL_OBJ_ID__BAL_OBJ_ID_TM_SCHED:
+            {
+          printf("\n*****************************************************\n");
+          printf("Received TM schedule msg\n");
+          printf("*****************************************************\n");
+            }
+            break;
     case BAL_OBJ_ID__BAL_OBJ_ID_PACKET:
        {
           switch(set_cfg->packet->key->packet_send_dest->type)
           {
              case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL:
                 {
-                   printf("\n*****************************************************\n");  
+                   printf("\n*****************************************************\n");
                    printf("Received OMCI msg\n");
-                   printf("*****************************************************\n");  
+                   printf("*****************************************************\n");
                    temp->intf_id = set_cfg->terminal->key->intf_id;
                    temp->onu_id = set_cfg->terminal->key->sub_term_id;
                 }
                 break;
              default:
                 {
-                   ("\n*****************************************************\n");  
+                   ("\n*****************************************************\n");
                    printf("Dest type invalid\n");
-                   printf("*****************************************************\n");  
+                   printf("*****************************************************\n");
                 }
                 break;
           }
@@ -182,9 +348,9 @@
        break;
     default:
        {
-          ("\n*****************************************************\n");  
-          printf("Received Invalid msg\n");
-          printf("*****************************************************\n");  
+          ("\n*****************************************************\n");
+          printf("Received Invalid msg type === %d \n", set_cfg->hdr->obj_type);
+          printf("*****************************************************\n");
                     pthread_mutex_unlock(&lock);
                     return;
        }
@@ -198,19 +364,19 @@
       printf("BALSTUB:Cfg Set recevied without object type");
    } */
    pthread_mutex_unlock(&lock);
-   sleep(2);   
+   sleep(2);
    pthread_cond_signal(&cv);
 /*
    if(BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE == set_cfg->hdr->obj_type)
    {
-      sleep(5); 
-      struct QNode *temp1 = newNode(BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL, 
-            BAL_ERRNO__BAL_ERR_OK, 
+      sleep(5);
+      struct QNode *temp1 = newNode(BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL,
+            BAL_ERRNO__BAL_ERR_OK,
             set_cfg->device_id);
       temp1->intf_id = set_cfg->interface->key->intf_id;
       temp1->onu_id = 65535;
       printf("sending _onu_discovery_indiaction\n");
-      enQueue(BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL, temp1); 
+      enQueue(BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL, temp1);
       pthread_cond_signal(&cv);
    }
 */
@@ -232,7 +398,7 @@
    BalKey *clear_key;
 
    /*
-    * Read incoming message into clear_key 
+    * Read incoming message into clear_key
     */
    if (context->gcc_payload) {
       context->gcc_stream->read(context, (void **)&clear_key, 0);
@@ -265,9 +431,9 @@
     */
 
 
-   ("\n*****************************************************\n");  
+   ("\n*****************************************************\n");
    printf("Received API Init msg\n");
-   printf("*****************************************************\n");  
+   printf("*****************************************************\n");
 
    bal_err__init(&bal_err);
 
@@ -279,12 +445,13 @@
    ret_val = context->gcc_stream->write(context, &bal_err, 0);
    if (ret_val != GRPC_C_WRITE_OK) {
       if(ret_val == GRPC_C_WRITE_PENDING) {
-         printf("write is pending, sleep for 10 sec: %d\n", ret_val);
+         printf("write is pending, sleep for 10 sec %d \n", ret_val);
          sleep(10);
       }
       else {
-         printf("Failed to write: %d\n", ret_val);
-         exit(1);
+         printf("Failed to write %d \n", ret_val);
+         printf("write is pending, sleep for 10 sec: %d\n", ret_val);
+         sleep(10);
       }
    }
 
@@ -403,53 +570,11 @@
 {
 }
 
-#if 0
-void bal__bal_api_heartbeat_cb(grpc_c_context_t *context)
-{
-   BalHeartbeat *bal_hb;
-   BalErr bal_err;
-
-   /*
-    * Read incoming message into set_cfg
-    */
-   printf("\nRecevied HeartBeat from Adapter\n");
-   if (context->gcc_payload) {
-	context->gcc_stream->read(context, (void **)&bal_hb, 0);
-   }
-
-   printf("Received Heart Beat msg\n");
-
-   bal_err__init(&bal_err);
-
-   bal_err.err= 0;
-
-   /*
-    * Write reply back to the client
-    */
-    if (!context->gcc_stream->write(context, &bal_err, 0)) {
-    } else {
-              printf("Failed to write\n");
-	      exit(1);
-    }
-
-    grpc_c_status_t status;
-    status.gcs_code = 0;
-
-    /*
-     * Finish response for RPC
-     */
-    if (context->gcc_stream->finish(context, &status)) {
-	printf("Failed to write status\n");
-	exit(1);
-    }
-   printf("\nSent HeartBeat Response to Adapter\n");
-}
-#endif
 
 /*
  * Takes socket path as argument
  */
-int main (int argc, char **argv) 
+int main (int argc, char **argv)
 {
    int i = 0;
    grpc_c_server_t *server = NULL;
@@ -483,7 +608,7 @@
    /*
     * Initialize greeter service
     */
-   printf("\nbal_voltha_app running.....\n");
+   printf("\nvoltha_bal_driver running.....\n");
    bal__service_init(test_server);
 
    /*
diff --git a/src/asfvolt16_driver.c b/src/asfvolt16_driver.c
index 1178ff2..24bca9d 100755
--- a/src/asfvolt16_driver.c
+++ b/src/asfvolt16_driver.c
@@ -95,6 +95,12 @@
     cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler )bal_omci_data_indication_cb;
     bcmbal_subscribe_ind(0, &cb_cfg);
 
+    /* Bearer Channel Data */
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_packet_data_indication_cb;
+    ind_subgroup = bcmbal_packet_auto_id_bearer_channel_rx;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
+
 #if 0
     /* Access Terminal Operational State Change */
     cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_acc_term_osc_indication_cb;
@@ -166,11 +172,6 @@
     cb_cfg.p_subgroup = &ind_subgroup;
     err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
     
-    /* Bearer Channel Data */
-    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_packet_data_indication_cb;
-    ind_subgroup = bcmbal_packet_auto_id_bearer_channel_rx;
-    cb_cfg.p_subgroup = &ind_subgroup;
-    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
     
     /* OAM Channel Data - oam response indication */
     cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_oam_data_indication_cb;
@@ -186,7 +187,7 @@
 /********************************************************************
  *                                                                  *
  *     gRPC service RPC function implementation                     *
- *                                                                  *   
+ *                                                                  *
  ********************************************************************/
 
 /********************************************************************\
@@ -215,7 +216,7 @@
     argv[2] = coreInfo->bal_core_ip_port;
     argv[3] = coreInfo->bal_core_arg2;
     argv[4] = coreInfo->bal_shared_lib_ip_port;
-    int argc = 5; 
+    int argc = 5;
     client = grpc_c_client_init(ip_and_port, "bal_client", NULL);
 
     /* Init BAL */
@@ -237,7 +238,7 @@
     }
 #endif
 
-    /* Register the call back functions to handle any 
+    /* Register the call back functions to handle any
      * indications from the BAL */
     bcmbal_cb_cfg cb_cfg = {};
     uint16_t ind_subgroup;
@@ -282,7 +283,7 @@
  *               1) Access Terminal Cfg                             *
  *               2) Interface(PON & NNI) Cfg                        *
  *               3) Subscriber Terminal (ONU) cfg                   *
- *               4) Flow Cfg                                        *             
+ *               4) Flow Cfg                                        *
  *               5) Group Cfg (In case of Multicast)                *
  ********************************************************************/
 uint32_t asfvolt16_bal_cfg_set(BalCfg *cfg)
@@ -349,7 +350,7 @@
  *               1) Access Terminal Cfg                             *
  *               2) Interface(PON & NNI) Cfg                        *
  *               3) Subscriber Terminal (ONU) cfg                   *
- *               4) Flow Cfg                                        *             
+ *               4) Flow Cfg                                        *
  *               5) Group Cfg (In case of Multicast)                *
  ********************************************************************/
 uint32_t asfvolt16_bal_cfg_clear(BalKey *key)
@@ -419,7 +420,7 @@
  *               1) Access Terminal Cfg                             *
  *               2) Interface(PON & NNI) Cfg                        *
  *               3) Subscriber Terminal (ONU) cfg                   *
- *               4) Flow Cfg                                        *             
+ *               4) Flow Cfg                                        *
  *               5) Group Cfg (In case of Multicast)                *
  ********************************************************************/
 uint32_t asfvolt16_bal_cfg_get(BalKey *key, BalCfg *cfg)
diff --git a/src/bal_indications_hdlr.c b/src/bal_indications_hdlr.c
index 1c34d6e..44c4620 100755
--- a/src/bal_indications_hdlr.c
+++ b/src/bal_indications_hdlr.c
@@ -18,7 +18,7 @@
 
 /*static bcmos_mutex bal_ind_lock; - Need to define bcm independent mutex*/
 /********************************************************************\
- * Function    : bal_acc_term_indication_cb                         * 
+ * Function    : bal_acc_term_indication_cb                         *
  * Description : This function will handle the indications for      *
  *               Access Terminal Indication                         *
  *                                                                  *
@@ -27,7 +27,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_ACCESS_TERMINAL != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_ACCESS_TERMINAL != obj->obj_type ||
       bcmbal_access_terminal_auto_id_ind != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -49,7 +49,6 @@
       balIndCfg.device_id = voltha_device_id;
 
       bcmbal_access_terminal_ind *acc_term_ind = (bcmbal_access_terminal_ind *)obj;
-      
 
       BalAccessTerminalInd acessTermInd;
       memset(&acessTermInd, 0, sizeof(BalAccessTerminalInd));
@@ -61,61 +60,61 @@
       bal_obj__init(&hdr);
       balIndCfg.access_term_ind->hdr = &hdr;
 
-      BalAccessTerminalKey accessTermkey; 
+      BalAccessTerminalKey accessTermkey;
       memset(&accessTermkey, 0, sizeof(BalAccessTerminalKey));
       bal_access_terminal_key__init(&accessTermkey);
-      balIndCfg.access_term_ind->key = &accessTermkey; 
+      balIndCfg.access_term_ind->key = &accessTermkey;
 
-      balIndCfg.access_term_ind->key->has_access_term_id = BAL_GRPC_PRES; 
+      balIndCfg.access_term_ind->key->has_access_term_id = BAL_GRPC_PRES;
       balIndCfg.access_term_ind->key->access_term_id = acc_term_ind->key.access_term_id;
-      
+
       BalAccessTerminalIndData accessTermIndData;
       memset(&accessTermIndData, 0, sizeof(BalAccessTerminalIndData));
       bal_access_terminal_ind_data__init(&accessTermIndData);
-      balIndCfg.access_term_ind->data = &accessTermIndData; 
+      balIndCfg.access_term_ind->data = &accessTermIndData;
 
-      balIndCfg.access_term_ind->data->has_admin_state = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->admin_state = acc_term_ind->data.admin_state; 
-      balIndCfg.access_term_ind->data->has_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->oper_status = acc_term_ind->data.oper_status; 
-      balIndCfg.access_term_ind->data->has_iwf_mode = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->iwf_mode = acc_term_ind->data.iwf_mode; 
+      balIndCfg.access_term_ind->data->has_admin_state = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->admin_state = acc_term_ind->data.admin_state;
+      balIndCfg.access_term_ind->data->has_oper_status = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->oper_status = acc_term_ind->data.oper_status;
+      balIndCfg.access_term_ind->data->has_iwf_mode = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->iwf_mode = acc_term_ind->data.iwf_mode;
 
       BalTopology balTop;
       memset(&balTop, 0, sizeof(BalTopology));
       bal_topology__init(&balTop);
-      balIndCfg.access_term_ind->data->topology = &balTop; 
+      balIndCfg.access_term_ind->data->topology = &balTop;
 
-      balIndCfg.access_term_ind->data->topology->has_num_of_nni_ports = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->topology->num_of_nni_ports = 
-                                            acc_term_ind->data.topology.num_of_nni_ports; 
-      balIndCfg.access_term_ind->data->topology->has_num_of_pon_ports = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->topology->num_of_pon_ports = 
-                                            acc_term_ind->data.topology.num_of_pon_ports; 
-      balIndCfg.access_term_ind->data->topology->has_num_of_mac_devs = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->topology->num_of_mac_devs = 
-                                             acc_term_ind->data.topology.num_of_mac_devs; 
-      balIndCfg.access_term_ind->data->topology->has_num_of_pons_per_mac_dev = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->topology->num_of_pons_per_mac_dev = 
-                                      acc_term_ind->data.topology.num_of_pons_per_mac_dev; 
-      balIndCfg.access_term_ind->data->topology->has_pon_family = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->topology->pon_family = 
-                                                   acc_term_ind->data.topology.pon_family; 
-      balIndCfg.access_term_ind->data->topology->has_pon_sub_family = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->topology->pon_sub_family = 
-                                                acc_term_ind->data.topology.pon_sub_family; 
+      balIndCfg.access_term_ind->data->topology->has_num_of_nni_ports = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->topology->num_of_nni_ports =
+                                            acc_term_ind->data.topology.num_of_nni_ports;
+      balIndCfg.access_term_ind->data->topology->has_num_of_pon_ports = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->topology->num_of_pon_ports =
+                                            acc_term_ind->data.topology.num_of_pon_ports;
+      balIndCfg.access_term_ind->data->topology->has_num_of_mac_devs = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->topology->num_of_mac_devs =
+                                             acc_term_ind->data.topology.num_of_mac_devs;
+      balIndCfg.access_term_ind->data->topology->has_num_of_pons_per_mac_dev = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->topology->num_of_pons_per_mac_dev =
+                                      acc_term_ind->data.topology.num_of_pons_per_mac_dev;
+      balIndCfg.access_term_ind->data->topology->has_pon_family = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->topology->pon_family =
+                                                   acc_term_ind->data.topology.pon_family;
+      balIndCfg.access_term_ind->data->topology->has_pon_sub_family = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->topology->pon_sub_family =
+                                                acc_term_ind->data.topology.pon_sub_family;
 
       BalSwVersion balsv;
       memset(&balsv, 0, sizeof(BalSwVersion));
       bal_sw_version__init(&balsv);
-      balIndCfg.access_term_ind->data->sw_version = &balsv; 
+      balIndCfg.access_term_ind->data->sw_version = &balsv;
 
-      balIndCfg.access_term_ind->data->sw_version->has_version_type = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->sw_version->version_type = 
-                                                acc_term_ind->data.sw_version.version_type; 
-      balIndCfg.access_term_ind->data->sw_version->has_major_rev = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->sw_version->major_rev = 
-                                                   acc_term_ind->data.sw_version.major_rev; 
+      balIndCfg.access_term_ind->data->sw_version->has_version_type = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->sw_version->version_type =
+                                                acc_term_ind->data.sw_version.version_type;
+      balIndCfg.access_term_ind->data->sw_version->has_major_rev = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->sw_version->major_rev =
+                                                   acc_term_ind->data.sw_version.major_rev;
       balIndCfg.access_term_ind->data->sw_version->has_minor_rev = BAL_GRPC_PRES; 
       balIndCfg.access_term_ind->data->sw_version->minor_rev = 
                                                    acc_term_ind->data.sw_version.minor_rev; 
@@ -1487,6 +1486,8 @@
       /*bcmos_mutex_lock(&bal_ind_lock);-- Need to define bcm independent mutex*/
 
       BalIndications balIndCfg;
+      memset(&balIndCfg, 0, sizeof(BalIndications));
+      bal_indications__init(&balIndCfg);
       balIndCfg.u_case = BAL_INDICATIONS__U_PKT_DATA;
       balIndCfg.has_objtype = BAL_GRPC_PRES;
       balIndCfg.objtype = obj->obj_type;
@@ -1596,6 +1597,7 @@
       balIndCfg.pktdata->data->flow_cookie = rx_channel->data.flow_cookie; 
       balIndCfg.pktdata->data->has_pkt = BAL_GRPC_PRES; 
       balIndCfg.pktdata->data->pkt.len = rx_channel->data.pkt.len;
+      balIndCfg.pktdata->data->pkt.data = (uint8_t *)malloc((balIndCfg.pktdata->data->pkt.len)*sizeof(uint8_t)); 
       memcpy(balIndCfg.pktdata->data->pkt.data,  rx_channel->data.pkt.val, balIndCfg.pktdata->data->pkt.len); 
 
       /*bcmos_mutex_unlock(&bal_ind_lock);-- Need to define bcm independent mutex*/