VOL-253: grpc-c was crashed if we configured wrong VOLTHA IP address
Fix for grpc-c crash, dying gas alarm, kpis and packet data

Change-Id: I172e64afa0f9e9c1492f4871b6fa7ae3152065cd
diff --git a/device_simulator/client.c.patch b/device_simulator/client.c.patch
index 7de4dd1..c77a281 100644
--- a/device_simulator/client.c.patch
+++ b/device_simulator/client.c.patch
@@ -35,3 +35,15 @@
   
       context = gc_client_prepare_ops(client, mdarray, 1, input, NULL, 
   				    client_streaming, server_streaming, NULL, 
+***************
+--- grpc-c_orig/lib/client.c    2017-09-19 21:08:29.506546198 +0530
++++ grpc-c/lib/client.c 2017-09-19 21:10:52.137702783 +0530
+@@ -967,7 +967,6 @@
+
+     if (*output == NULL) {
+        grpc_c_context_free(context);
+-       gpr_log(GPR_ERROR, "No output to return");
+        rc = GRPC_C_FAIL;
+        goto cleanup;
+     }
+
diff --git a/device_simulator/voltha_bal_driver.c b/device_simulator/voltha_bal_driver.c
index afdb73e..2d59e0e 100755
--- a/device_simulator/voltha_bal_driver.c
+++ b/device_simulator/voltha_bal_driver.c
@@ -51,7 +51,7 @@
 {
    BalHeartbeat *bal_hb;
    BalErr bal_err;
-
+   int ret_val;
    /*
     * Read incoming message into set_cfg
     */
@@ -69,11 +69,18 @@
    /*
     * Write reply back to the client
     */
-    if (!context->gcc_stream->write(context, &bal_err, 0)) {
-    } else {
-              printf("Failed to write\n");
-	      exit(1);
-    }
+   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(%d) is pending, sleep for 5 sec\n", ret_val);
+         sleep(5);
+      }
+      else {
+         printf("Failed to write %d \n", ret_val);
+         printf("write(%d) is pending, sleep for 5 sec\n", ret_val);
+         sleep(5);
+      }
+   }
 
     grpc_c_status_t status;
     status.gcs_code = 0;
@@ -97,6 +104,8 @@
 {
    BalReboot *read_device;
    BalErr bal_err;
+   int ret_val;
+
    /*
     * Read incoming message into get_cfg
     */
@@ -122,10 +131,17 @@
    /*
     * 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);
+   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(%d) is pending, sleep for 5 sec\n", ret_val);
+         sleep(5);
+      }
+      else {
+         printf("Failed to write %d \n", ret_val);
+         printf("write(%d) is pending, sleep for 5 sec\n", ret_val);
+         sleep(5);
+      }
    }
 
    grpc_c_status_t status;
@@ -146,6 +162,7 @@
 void bal__bal_cfg_stat_get_cb(grpc_c_context_t *context)
 {
     BalInterfaceKey *read_stats;
+    int ret_val;
 
     /*
     * Read incoming message into get_cfg
@@ -180,8 +197,18 @@
     if (!context->gcc_stream->write(context, &get_stats, 0)) {
 	   printf("Successfully Written Stats\n");
     } else {
-       printf("Stats Failed to write\n");
-	   exit(1);
+	    if (ret_val != GRPC_C_WRITE_OK) {
+		    if(ret_val == GRPC_C_WRITE_PENDING) {
+			    printf("write(%d) is pending, sleep for 5 sec\n", ret_val);
+			    sleep(5);
+		    }
+		    else {
+			    printf("Failed to write %d \n", ret_val);
+			    printf("write(%d) is pending, sleep for 5 sec\n", ret_val);
+			    sleep(5);
+		    }
+	    }
+
     }
 
     grpc_c_status_t status;
@@ -195,8 +222,8 @@
         exit(1);
     }
 
-    sleep(1);
     printf("============ Returning from Stats Function============\n");
+    sleep(1);
 }
 
 /*
@@ -249,13 +276,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);
-         sleep(10);
+         printf("write(%d) is pending, sleep for 5 sec \n", ret_val);
+         sleep(5);
       }
       else {
          printf("Failed to write %d \n", ret_val);
-         printf("write is pending, sleep for 10 sec: %d\n", ret_val);
-         sleep(10);
+         printf("write(%d) is pending, sleep for 5 sec \n", ret_val);
+         sleep(5);
       }
    }
 
@@ -338,7 +365,7 @@
                 break;
              default:
                 {
-                   ("\n*****************************************************\n");
+                   printf("\n*****************************************************\n");
                    printf("Dest type invalid\n");
                    printf("*****************************************************\n");
                 }
@@ -348,7 +375,7 @@
        break;
     default:
        {
-          ("\n*****************************************************\n");
+          printf("\n*****************************************************\n");
           printf("Received Invalid msg type === %d \n", set_cfg->hdr->obj_type);
           printf("*****************************************************\n");
                     pthread_mutex_unlock(&lock);
@@ -431,7 +458,7 @@
     */
 
 
-   ("\n*****************************************************\n");
+   printf("\n*****************************************************\n");
    printf("Received API Init msg\n");
    printf("*****************************************************\n");
 
@@ -445,13 +472,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);
-         sleep(10);
+         printf("write(%d) is pending, sleep for 5 sec\n", ret_val);
+         sleep(5);
       }
       else {
          printf("Failed to write %d \n", ret_val);
-         printf("write is pending, sleep for 10 sec: %d\n", ret_val);
-         sleep(10);
+         printf("write(%d) is pending, sleep for 5 sec\n", ret_val);
+         sleep(5);
       }
    }
 
diff --git a/src/asfvolt16_driver.c b/src/asfvolt16_driver.c
index 24bca9d..662c94c 100755
--- a/src/asfvolt16_driver.c
+++ b/src/asfvolt16_driver.c
@@ -47,6 +47,13 @@
 
     cb_cfg.module = BCMOS_MODULE_ID_NONE;
 
+    /* Access Terminal Operational State Change */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_ACCESS_TERMINAL;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_acc_term_osc_indication_cb;
+    ind_subgroup = bcmbal_access_terminal_auto_id_oper_status_change;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
+
     /* Register to get indications for interface objects
      */
     cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
@@ -63,6 +70,12 @@
     cb_cfg.p_subgroup = &ind_subgroup;
     err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
 
+    /* Interface Operational State Change */
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_osc_indication_cb;
+    ind_subgroup = bcmbal_interface_auto_id_oper_status_change;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
+
     /* Register to get indications for subscriber terminal objects
      */
     cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
@@ -73,6 +86,12 @@
     cb_cfg.p_subgroup = &ind_subgroup;
     err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
 
+    /* Subscriber Terminal dgi */
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_dgi_indication_cb;
+    ind_subgroup = bcmbal_subscriber_terminal_auto_id_dgi;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
+
     /* Subscriber Terminal Discovery */
     cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_disc_indication_cb;
     ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_disc;
@@ -85,6 +104,12 @@
     cb_cfg.p_subgroup = &ind_subgroup;
     err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
 
+    /* Subscriber Terminal Operational State Change */
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_osc_indication_cb;
+    ind_subgroup = bcmbal_subscriber_terminal_auto_id_oper_status_change;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
+
     /* Register to get indication callbacks for OMCI objects
      */
     cb_cfg.obj_type = BCMBAL_OBJ_ID_PACKET;
@@ -100,14 +125,13 @@
     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;
-    ind_subgroup = bcmbal_access_terminal_auto_id_oper_status_change;
+    /* OAM Channel Data - oam response indication */
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_oam_data_indication_cb;
+    ind_subgroup = bcmbal_packet_auto_id_ieee_oam_channel_rx;
     cb_cfg.p_subgroup = &ind_subgroup;
     err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
-
+#endif
     /* Register to get indication callbacks for flow objects
      */
     cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
@@ -124,38 +148,6 @@
     cb_cfg.p_subgroup = &ind_subgroup;
     err = bcmbal_subscribe_ind(access_term_id, &cb_cfg);
 
-    /* Register to get indication callbacks for group objects
-     */
-    cb_cfg.obj_type = BCMBAL_OBJ_ID_GROUP;
-    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_group_indication_cb;
-    ind_subgroup = bcmbal_group_auto_id_ind;
-    cb_cfg.p_subgroup = &ind_subgroup;
-    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
-    
-    /* Interface Operational State Change */
-    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_osc_indication_cb;
-    ind_subgroup = bcmbal_interface_auto_id_oper_status_change;
-    cb_cfg.p_subgroup = &ind_subgroup;
-    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
-
-    /* Interface los */
-    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_interface_los_indication_cb;
-    ind_subgroup = bcmbal_interface_auto_id_los;
-    cb_cfg.p_subgroup = &ind_subgroup;
-    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
-
-    /* Subscriber Terminal Operational State Change */
-    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_osc_indication_cb;
-    ind_subgroup = bcmbal_subscriber_terminal_auto_id_oper_status_change;
-    cb_cfg.p_subgroup = &ind_subgroup;
-    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
-
-    /* Subscriber Terminal dgi */
-    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_sub_term_dgi_indication_cb;
-    ind_subgroup = bcmbal_subscriber_terminal_auto_id_dgi;
-    cb_cfg.p_subgroup = &ind_subgroup;
-    err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
-
     /* Register to get indication callbacks for tm queue objects
      */
     cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_QUEUE;
@@ -171,15 +163,14 @@
     ind_subgroup = bcmbal_tm_sched_auto_id_ind;
     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;
-    ind_subgroup = bcmbal_packet_auto_id_ieee_oam_channel_rx;
+
+    /* Register to get indication callbacks for group objects
+     */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_GROUP;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)bal_group_indication_cb;
+    ind_subgroup = bcmbal_group_auto_id_ind;
     cb_cfg.p_subgroup = &ind_subgroup;
     err = err ? err : bcmbal_subscribe_ind(access_term_id, &cb_cfg);
-    
-#endif
     return err;
 }
 
diff --git a/src/bal_indications_hdlr.c b/src/bal_indications_hdlr.c
index 44c4620..8f13e88 100755
--- a/src/bal_indications_hdlr.c
+++ b/src/bal_indications_hdlr.c
@@ -36,7 +36,7 @@
    }
    else
    {
-      ASFVOLT_LOG(ASFVOLT_DEBUG, "suhas:Processing BAL API \'%s\' IND callback (status is %s)\n",
+      ASFVOLT_LOG(ASFVOLT_DEBUG, "Processing BAL API \'%s\' IND callback (status is %s)\n",
 				  bcmbal_objtype_str(obj->obj_type), bcmos_strerror(obj->status));
       BalIndications balIndCfg;
       memset(&balIndCfg, 0, sizeof(BalIndications));
@@ -115,20 +115,20 @@
       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; 
-      balIndCfg.access_term_ind->data->sw_version->has_patch_rev = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->sw_version->patch_rev = 
-                                                   acc_term_ind->data.sw_version.patch_rev; 
-      balIndCfg.access_term_ind->data->sw_version->has_om_version = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->sw_version->om_version = 
-                                                  acc_term_ind->data.sw_version.om_version; 
-      balIndCfg.access_term_ind->data->sw_version->has_dev_point = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind->data->sw_version->dev_point = 
-                                                   acc_term_ind->data.sw_version.dev_point; 
-      
-      bal_register_indication_cbs(); 
+      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;
+      balIndCfg.access_term_ind->data->sw_version->has_patch_rev = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->sw_version->patch_rev =
+                                                   acc_term_ind->data.sw_version.patch_rev;
+      balIndCfg.access_term_ind->data->sw_version->has_om_version = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->sw_version->om_version =
+                                                  acc_term_ind->data.sw_version.om_version;
+      balIndCfg.access_term_ind->data->sw_version->has_dev_point = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind->data->sw_version->dev_point =
+                                                   acc_term_ind->data.sw_version.dev_point;
+
+      bal_register_indication_cbs();
 
       BalErr *output;
       result = bal_ind__bal_acc_term_ind(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -138,7 +138,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_acc_term_osc_indication_cb                     * 
+ * Function    : bal_acc_term_osc_indication_cb                     *
  * Description : This function will handle the indications for      *
  *               Access Terminal Operational State Change           *
  *                                                                  *
@@ -147,7 +147,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_oper_status_change != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -166,7 +166,7 @@
       balIndCfg.u_case = BAL_INDICATIONS__U_ACCESS_TERM_IND_OP_STATE;
       balIndCfg.device_id = voltha_device_id;
 
-      bcmbal_access_terminal_oper_status_change *acc_term_osc = 
+      bcmbal_access_terminal_oper_status_change *acc_term_osc =
                                   (bcmbal_access_terminal_oper_status_change *)obj;
 
       BalAccessTerminalOperStatusChange acessTermOSC;
@@ -174,29 +174,34 @@
       bal_access_terminal_oper_status_change__init(&acessTermOSC);
       balIndCfg.access_term_ind_op_state = &acessTermOSC;
 
-      BalAccessTerminalKey accessTermkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.access_term_ind_op_state->hdr = &hdr;
+
+      BalAccessTerminalKey accessTermkey;
       memset(&accessTermkey, 0, sizeof(BalAccessTerminalKey));
       bal_access_terminal_key__init(&accessTermkey);
-      balIndCfg.access_term_ind_op_state->key = &accessTermkey; 
+      balIndCfg.access_term_ind_op_state->key = &accessTermkey;
 
-      balIndCfg.access_term_ind_op_state->key->has_access_term_id = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind_op_state->key->access_term_id = 
+      balIndCfg.access_term_ind_op_state->key->has_access_term_id = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind_op_state->key->access_term_id =
                                                   acc_term_osc->key.access_term_id;
-      
+
       BalAccessTerminalOperStatusChangeData accessTermOscData;
       memset(&accessTermOscData, 0, sizeof(BalAccessTerminalOperStatusChangeData));
       bal_access_terminal_oper_status_change_data__init(&accessTermOscData);
-      balIndCfg.access_term_ind_op_state->data = &accessTermOscData; 
+      balIndCfg.access_term_ind_op_state->data = &accessTermOscData;
 
-      balIndCfg.access_term_ind_op_state->data->has_new_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind_op_state->data->new_oper_status = 
-                                                 acc_term_osc->data.new_oper_status; 
-      balIndCfg.access_term_ind_op_state->data->has_old_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind_op_state->data->old_oper_status = 
-                                                 acc_term_osc->data.old_oper_status; 
-      balIndCfg.access_term_ind_op_state->data->has_admin_state = BAL_GRPC_PRES; 
-      balIndCfg.access_term_ind_op_state->data->admin_state = 
-                                                 acc_term_osc->data.admin_state; 
+      balIndCfg.access_term_ind_op_state->data->has_new_oper_status = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind_op_state->data->new_oper_status =
+                                                 acc_term_osc->data.new_oper_status;
+      balIndCfg.access_term_ind_op_state->data->has_old_oper_status = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind_op_state->data->old_oper_status =
+                                                 acc_term_osc->data.old_oper_status;
+      balIndCfg.access_term_ind_op_state->data->has_admin_state = BAL_GRPC_PRES;
+      balIndCfg.access_term_ind_op_state->data->admin_state =
+                                                 acc_term_osc->data.admin_state;
 
       BalErr *output;
       result = bal_ind__bal_acc_term_oper_sts_cng_ind(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -206,7 +211,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_flow_osc_indication_cb                         * 
+ * Function    : bal_flow_osc_indication_cb                         *
  * Description : This function will handle the indications for      *
  *               Flow Operational State Change                      *
  *                                                                  *
@@ -215,7 +220,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_FLOW != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_FLOW != obj->obj_type ||
       bcmbal_flow_auto_id_oper_status_change != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -241,33 +246,38 @@
       bal_flow_oper_status_change__init(&flowOscInd);
       balIndCfg.flow_op_state = &flowOscInd;
 
-      BalFlowKey flowkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.flow_op_state->hdr = &hdr;
+
+      BalFlowKey flowkey;
       memset(&flowkey, 0, sizeof(BalFlowKey));
       bal_flow_key__init(&flowkey);
-      balIndCfg.flow_op_state->key = &flowkey; 
+      balIndCfg.flow_op_state->key = &flowkey;
 
-      balIndCfg.flow_op_state->key->has_flow_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->key->flow_id = flow_osc->key.flow_id; 
-      balIndCfg.flow_op_state->key->has_flow_type = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->key->flow_type = flow_osc->key.flow_type; 
-      
+      balIndCfg.flow_op_state->key->has_flow_id = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->key->flow_id = flow_osc->key.flow_id;
+      balIndCfg.flow_op_state->key->has_flow_type = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->key->flow_type = flow_osc->key.flow_type;
+
       BalFlowOperStatusChangeData flowOscIndData;
       memset(&flowOscIndData, 0, sizeof(BalFlowOperStatusChangeData));
       bal_flow_oper_status_change_data__init(&flowOscIndData);
-      balIndCfg.flow_op_state->data = &flowOscIndData; 
+      balIndCfg.flow_op_state->data = &flowOscIndData;
 
-      balIndCfg.flow_op_state->data->has_new_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->data->new_oper_status = flow_osc->data.new_oper_status; 
-      balIndCfg.flow_op_state->data->has_old_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->data->old_oper_status = flow_osc->data.old_oper_status; 
-      balIndCfg.flow_op_state->data->has_admin_state = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->data->admin_state = flow_osc->data.admin_state; 
-      balIndCfg.flow_op_state->data->has_svc_port_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->data->svc_port_id = flow_osc->data.svc_port_id; 
-      balIndCfg.flow_op_state->data->has_dba_tm_sched_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->data->dba_tm_sched_id = flow_osc->data.dba_tm_sched_id; 
-      balIndCfg.flow_op_state->data->has_cookie = BAL_GRPC_PRES; 
-      balIndCfg.flow_op_state->data->cookie = flow_osc->data.cookie; 
+      balIndCfg.flow_op_state->data->has_new_oper_status = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->data->new_oper_status = flow_osc->data.new_oper_status;
+      balIndCfg.flow_op_state->data->has_old_oper_status = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->data->old_oper_status = flow_osc->data.old_oper_status;
+      balIndCfg.flow_op_state->data->has_admin_state = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->data->admin_state = flow_osc->data.admin_state;
+      balIndCfg.flow_op_state->data->has_svc_port_id = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->data->svc_port_id = flow_osc->data.svc_port_id;
+      balIndCfg.flow_op_state->data->has_dba_tm_sched_id = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->data->dba_tm_sched_id = flow_osc->data.dba_tm_sched_id;
+      balIndCfg.flow_op_state->data->has_cookie = BAL_GRPC_PRES;
+      balIndCfg.flow_op_state->data->cookie = flow_osc->data.cookie;
 
       BalErr *output;
       result = bal_ind__bal_flow_oper_sts_cng(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -277,7 +287,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_flow_indication_cb                             * 
+ * Function    : bal_flow_indication_cb                             *
  * Description : This function will handle the indications for      *
  *               Flow Indication                                    *
  *                                                                  *
@@ -286,7 +296,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_FLOW != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_FLOW != obj->obj_type ||
       bcmbal_flow_auto_id_ind != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -312,44 +322,49 @@
       bal_flow_ind__init(&flowInd);
       balIndCfg.flow_ind = &flowInd;
 
-      BalFlowKey flowkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.flow_ind->hdr = &hdr;
+
+      BalFlowKey flowkey;
       memset(&flowkey, 0, sizeof(BalFlowKey));
       bal_flow_key__init(&flowkey);
-      balIndCfg.flow_ind->key = &flowkey; 
+      balIndCfg.flow_ind->key = &flowkey;
 
-      balIndCfg.flow_ind->key->has_flow_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->key->flow_id = flow_ind->key.flow_id; 
-      balIndCfg.flow_ind->key->has_flow_type = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->key->flow_type = flow_ind->key.flow_type; 
-      
+      balIndCfg.flow_ind->key->has_flow_id = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->key->flow_id = flow_ind->key.flow_id;
+      balIndCfg.flow_ind->key->has_flow_type = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->key->flow_type = flow_ind->key.flow_type;
+
       BalFlowIndData flowIndData;
       memset(&flowIndData, 0, sizeof(BalFlowIndData));
       bal_flow_ind_data__init(&flowIndData);
-      balIndCfg.flow_ind->data = &flowIndData; 
+      balIndCfg.flow_ind->data = &flowIndData;
 
-      balIndCfg.flow_ind->data->has_admin_state = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->admin_state = flow_ind->data.admin_state; 
-      balIndCfg.flow_ind->data->has_oper_status= BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->oper_status= flow_ind->data.oper_status; 
-      balIndCfg.flow_ind->data->has_access_int_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->access_int_id = flow_ind->data.access_int_id; 
-      balIndCfg.flow_ind->data->has_network_int_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->network_int_id = flow_ind->data.network_int_id; 
-      balIndCfg.flow_ind->data->has_sub_term_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->sub_term_id = flow_ind->data.sub_term_id; 
-      balIndCfg.flow_ind->data->has_sub_term_uni_idx = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->sub_term_uni_idx = flow_ind->data.sub_term_uni_idx; 
-      balIndCfg.flow_ind->data->has_svc_port_id = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->svc_port_id = flow_ind->data.svc_port_id; 
-      balIndCfg.flow_ind->data->has_resolve_mac = BAL_GRPC_PRES; 
-      balIndCfg.flow_ind->data->resolve_mac = flow_ind->data.resolve_mac; 
-      balIndCfg.flow_ind->data->has_cookie = BAL_GRPC_PRES; 
+      balIndCfg.flow_ind->data->has_admin_state = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->admin_state = flow_ind->data.admin_state;
+      balIndCfg.flow_ind->data->has_oper_status= BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->oper_status= flow_ind->data.oper_status;
+      balIndCfg.flow_ind->data->has_access_int_id = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->access_int_id = flow_ind->data.access_int_id;
+      balIndCfg.flow_ind->data->has_network_int_id = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->network_int_id = flow_ind->data.network_int_id;
+      balIndCfg.flow_ind->data->has_sub_term_id = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->sub_term_id = flow_ind->data.sub_term_id;
+      balIndCfg.flow_ind->data->has_sub_term_uni_idx = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->sub_term_uni_idx = flow_ind->data.sub_term_uni_idx;
+      balIndCfg.flow_ind->data->has_svc_port_id = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->svc_port_id = flow_ind->data.svc_port_id;
+      balIndCfg.flow_ind->data->has_resolve_mac = BAL_GRPC_PRES;
+      balIndCfg.flow_ind->data->resolve_mac = flow_ind->data.resolve_mac;
+      balIndCfg.flow_ind->data->has_cookie = BAL_GRPC_PRES;
       balIndCfg.flow_ind->data->cookie = flow_ind->data.cookie;
 
-      BalClassifier balClassifier; 
+      BalClassifier balClassifier;
       memset(&balClassifier, 0, sizeof(BalClassifier));
       bal_classifier__init(&balClassifier);
-      balIndCfg.flow_ind->data->classifier = &balClassifier; 
+      balIndCfg.flow_ind->data->classifier = &balClassifier;
 
       balIndCfg.flow_ind->data->classifier->has_presence_mask = BAL_GRPC_PRES;
       balIndCfg.flow_ind->data->classifier->presence_mask = flow_ind->data.classifier.presence_mask;
@@ -368,16 +383,20 @@
       balIndCfg.flow_ind->data->classifier->has_ether_type = BAL_GRPC_PRES;
       balIndCfg.flow_ind->data->classifier->ether_type = flow_ind->data.classifier.ether_type;
       balIndCfg.flow_ind->data->classifier->has_dst_mac = BAL_GRPC_PRES;
-      balIndCfg.flow_ind->data->classifier->dst_mac.len = 
+      balIndCfg.flow_ind->data->classifier->dst_mac.len =
                             (BCMOS_ETH_ALEN)*sizeof(flow_ind->data.classifier.dst_mac.u8);
-      memcpy(balIndCfg.flow_ind->data->classifier->dst_mac.data, 
-             flow_ind->data.classifier.dst_mac.u8, 
+      balIndCfg.flow_ind->data->classifier->dst_mac.data =
+           (uint8_t *)malloc((balIndCfg.flow_ind->data->classifier->dst_mac.len)*sizeof(uint8_t));
+      memcpy(balIndCfg.flow_ind->data->classifier->dst_mac.data,
+             flow_ind->data.classifier.dst_mac.u8,
              balIndCfg.flow_ind->data->classifier->dst_mac.len);
       balIndCfg.flow_ind->data->classifier->has_src_mac = BAL_GRPC_PRES;
-      balIndCfg.flow_ind->data->classifier->src_mac.len = 
+      balIndCfg.flow_ind->data->classifier->src_mac.len =
                             (BCMOS_ETH_ALEN)*sizeof(flow_ind->data.classifier.src_mac.u8);
-      memcpy(balIndCfg.flow_ind->data->classifier->src_mac.data, 
-             flow_ind->data.classifier.src_mac.u8, 
+      balIndCfg.flow_ind->data->classifier->src_mac.data =
+           (uint8_t *)malloc((balIndCfg.flow_ind->data->classifier->src_mac.len)*sizeof(uint8_t));
+      memcpy(balIndCfg.flow_ind->data->classifier->src_mac.data,
+             flow_ind->data.classifier.src_mac.u8,
              balIndCfg.flow_ind->data->classifier->src_mac.len);
       balIndCfg.flow_ind->data->classifier->has_ip_proto = BAL_GRPC_PRES;
       balIndCfg.flow_ind->data->classifier->ip_proto = flow_ind->data.classifier.ip_proto;
@@ -392,10 +411,10 @@
       balIndCfg.flow_ind->data->classifier->has_pkt_tag_type = BAL_GRPC_PRES;
       balIndCfg.flow_ind->data->classifier->pkt_tag_type = flow_ind->data.classifier.pkt_tag_type;
 
-      BalAction balAction; 
+      BalAction balAction;
       memset(&balAction, 0, sizeof(BalAction));
       bal_action__init(&balAction);
-      balIndCfg.flow_ind->data->action = &balAction; 
+      balIndCfg.flow_ind->data->action = &balAction;
 
       balIndCfg.flow_ind->data->action->has_presence_mask = BAL_GRPC_PRES;
       balIndCfg.flow_ind->data->action->presence_mask = flow_ind->data.action.presence_mask;
@@ -421,7 +440,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_group_indication_cb                            * 
+ * Function    : bal_group_indication_cb                            *
  * Description : This function will handle the indications for      *
  *               Group Indication                                   *
  *                                                                  *
@@ -430,7 +449,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_GROUP != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_GROUP != obj->obj_type ||
       bcmbal_group_auto_id_ind != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -456,25 +475,30 @@
       bal_group_ind__init(&groupInd);
       balIndCfg.group_ind = &groupInd;
 
-      BalGroupKey groupkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.group_ind->hdr = &hdr;
+
+      BalGroupKey groupkey;
       memset(&groupkey, 0, sizeof(BalGroupKey));
       bal_group_key__init(&groupkey);
-      balIndCfg.group_ind->key = &groupkey; 
+      balIndCfg.group_ind->key = &groupkey;
 
-      balIndCfg.group_ind->key->has_group_id = BAL_GRPC_PRES; 
-      balIndCfg.group_ind->key->group_id = group_ind->key.group_id; 
-      
+      balIndCfg.group_ind->key->has_group_id = BAL_GRPC_PRES;
+      balIndCfg.group_ind->key->group_id = group_ind->key.group_id;
+
       BalGroupIndData groupIndData;
       memset(&groupIndData, 0, sizeof(BalGroupIndData));
       bal_group_ind_data__init(&groupIndData);
-      balIndCfg.group_ind->data = &groupIndData; 
+      balIndCfg.group_ind->data = &groupIndData;
 
-      balIndCfg.group_ind->data->has_members_cmd = BAL_GRPC_PRES; 
-      balIndCfg.group_ind->data->members_cmd = group_ind->data.members_cmd; 
-      balIndCfg.group_ind->data->has_cookie = BAL_GRPC_PRES; 
-      balIndCfg.group_ind->data->cookie = group_ind->data.cookie; 
-      balIndCfg.group_ind->data->has_owner = BAL_GRPC_PRES; 
-      balIndCfg.group_ind->data->owner = group_ind->data.owner; 
+      balIndCfg.group_ind->data->has_members_cmd = BAL_GRPC_PRES;
+      balIndCfg.group_ind->data->members_cmd = group_ind->data.members_cmd;
+      balIndCfg.group_ind->data->has_cookie = BAL_GRPC_PRES;
+      balIndCfg.group_ind->data->cookie = group_ind->data.cookie;
+      balIndCfg.group_ind->data->has_owner = BAL_GRPC_PRES;
+      balIndCfg.group_ind->data->owner = group_ind->data.owner;
 
       BalGroupMemberInfoList balMembers;
       memset(&balMembers, 0, sizeof(BalGroupMemberInfoList));
@@ -488,16 +512,16 @@
       memset(&balMemberInfo, 0, sizeof(BalGroupMemberInfo));
       bal_group_member_info__init(balMemberInfo);
       balIndCfg.group_ind->data->members->val = &balMemberInfo;
-    
-      balMemberInfo->has_intf_id = BAL_GRPC_PRES; 
-      balMemberInfo->intf_id = group_ind->data.members.val->intf_id; 
-      balMemberInfo->has_svc_port_id = BAL_GRPC_PRES; 
-      balMemberInfo->svc_port_id = group_ind->data.members.val->svc_port_id; 
 
-      BalAction balAction; 
+      balMemberInfo->has_intf_id = BAL_GRPC_PRES;
+      balMemberInfo->intf_id = group_ind->data.members.val->intf_id;
+      balMemberInfo->has_svc_port_id = BAL_GRPC_PRES;
+      balMemberInfo->svc_port_id = group_ind->data.members.val->svc_port_id;
+
+      BalAction balAction;
       memset(&balAction, 0, sizeof(BalAction));
       bal_action__init(&balAction);
-      balMemberInfo->action = &balAction; 
+      balMemberInfo->action = &balAction;
 
       balMemberInfo->action->has_presence_mask = BAL_GRPC_PRES;
       balMemberInfo->action->presence_mask = group_ind->data.members.val->action.presence_mask;
@@ -519,7 +543,7 @@
       BalTmQueueRef balQueue;
       memset(&balQueue, 0, sizeof(BalTmQueueRef));
       bal_tm_queue_ref__init(&balQueue);
-      balMemberInfo->queue = &balQueue; 
+      balMemberInfo->queue = &balQueue;
 
       balMemberInfo->queue->has_sched_id = BAL_GRPC_PRES;
       balMemberInfo->queue->sched_id = group_ind->data.members.val->queue.sched_id;
@@ -532,6 +556,8 @@
       balIndCfg.group_ind->data->flows = &balFlows;
 
       balIndCfg.group_ind->data->flows->n_val =  group_ind->data.flows.len;
+      balIndCfg.group_ind->data->flows->val =
+           (uint32_t *)malloc((balIndCfg.group_ind->data->flows->n_val)*sizeof(uint32_t));
       memcpy(balIndCfg.group_ind->data->flows->val, group_ind->data.flows.val,
              balIndCfg.group_ind->data->flows->n_val);
 
@@ -543,7 +569,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_interface_osc_indication_cb                    * 
+ * Function    : bal_interface_osc_indication_cb                    *
  * Description : This function will handle the indications for      *
  *               Interface Operational State Change                 *
  *                                                                  *
@@ -552,7 +578,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_INTERFACE != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_INTERFACE != obj->obj_type ||
       bcmbal_interface_auto_id_oper_status_change != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -571,7 +597,7 @@
       balIndCfg.sub_group = obj->subgroup;
       balIndCfg.device_id = voltha_device_id;
 
-      bcmbal_interface_oper_status_change *int_osc_ind = 
+      bcmbal_interface_oper_status_change *int_osc_ind =
                                  (bcmbal_interface_oper_status_change *)obj;
 
       BalInterfaceOperStatusChange ifOsc;
@@ -579,28 +605,33 @@
       bal_interface_oper_status_change__init(&ifOsc);
       balIndCfg.interface_op_state = &ifOsc;
 
-      BalInterfaceKey ifkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.interface_op_state->hdr = &hdr;
+
+      BalInterfaceKey ifkey;
       memset(&ifkey, 0, sizeof(BalInterfaceKey));
       bal_interface_key__init(&ifkey);
-      balIndCfg.interface_op_state->key = &ifkey; 
+      balIndCfg.interface_op_state->key = &ifkey;
 
-      balIndCfg.interface_op_state->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.interface_op_state->key->intf_id = int_osc_ind->key.intf_id; 
-      balIndCfg.interface_op_state->key->has_intf_type = BAL_GRPC_PRES; 
-      balIndCfg.interface_op_state->key->intf_type = int_osc_ind->key.intf_type; 
-      
+      balIndCfg.interface_op_state->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.interface_op_state->key->intf_id = int_osc_ind->key.intf_id;
+      balIndCfg.interface_op_state->key->has_intf_type = BAL_GRPC_PRES;
+      balIndCfg.interface_op_state->key->intf_type = int_osc_ind->key.intf_type;
+
       BalInterfaceOperStatusChangeData ifOscIndData;
       memset(&ifOscIndData, 0, sizeof(BalInterfaceOperStatusChangeData));
       bal_interface_oper_status_change_data__init(&ifOscIndData);
-      balIndCfg.interface_op_state->data = &ifOscIndData; 
+      balIndCfg.interface_op_state->data = &ifOscIndData;
 
-      balIndCfg.interface_op_state->data->has_new_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.interface_op_state->data->new_oper_status = int_osc_ind->data.new_oper_status; 
-      balIndCfg.interface_op_state->data->has_old_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.interface_op_state->data->old_oper_status = int_osc_ind->data.old_oper_status; 
-      balIndCfg.interface_op_state->data->has_admin_state = BAL_GRPC_PRES; 
+      balIndCfg.interface_op_state->data->has_new_oper_status = BAL_GRPC_PRES;
+      balIndCfg.interface_op_state->data->new_oper_status = int_osc_ind->data.new_oper_status;
+      balIndCfg.interface_op_state->data->has_old_oper_status = BAL_GRPC_PRES;
+      balIndCfg.interface_op_state->data->old_oper_status = int_osc_ind->data.old_oper_status;
+      balIndCfg.interface_op_state->data->has_admin_state = BAL_GRPC_PRES;
       balIndCfg.interface_op_state->data->admin_state = int_osc_ind->data.admin_state;
- 
+
       BalErr *output;
       result = bal_ind__bal_iface_oper_sts_cng(client, NULL, &balIndCfg, &output, NULL, 0);
    }
@@ -609,7 +640,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_interface_los_indication_cb                    * 
+ * Function    : bal_interface_los_indication_cb                    *
  * Description : This function will handle the indications for      *
  *               Interface los Indication                           *
  *                                                                  *
@@ -618,7 +649,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_INTERFACE != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_INTERFACE != obj->obj_type ||
       bcmbal_interface_auto_id_los != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -637,7 +668,7 @@
       balIndCfg.sub_group = obj->subgroup;
       balIndCfg.device_id = voltha_device_id;
 
-      bcmbal_interface_los *int_los_ind = 
+      bcmbal_interface_los *int_los_ind =
                                  (bcmbal_interface_los *)obj;
 
       BalInterfaceLos ifLos;
@@ -650,23 +681,23 @@
       bal_obj__init(&hdr);
       balIndCfg.interface_los->hdr = &hdr;
 
-      BalInterfaceKey ifkey; 
+      BalInterfaceKey ifkey;
       memset(&ifkey, 0, sizeof(BalInterfaceKey));
       bal_interface_key__init(&ifkey);
-      balIndCfg.interface_los->key = &ifkey; 
+      balIndCfg.interface_los->key = &ifkey;
 
-      balIndCfg.interface_los->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.interface_los->key->intf_id = int_los_ind->key.intf_id; 
-      balIndCfg.interface_los->key->has_intf_type = BAL_GRPC_PRES; 
-      balIndCfg.interface_los->key->intf_type = int_los_ind->key.intf_type; 
-      
+      balIndCfg.interface_los->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.interface_los->key->intf_id = int_los_ind->key.intf_id;
+      balIndCfg.interface_los->key->has_intf_type = BAL_GRPC_PRES;
+      balIndCfg.interface_los->key->intf_type = int_los_ind->key.intf_type;
+
       BalInterfaceLosData ifLosIndData;
       memset(&ifLosIndData, 0, sizeof(BalInterfaceLosData));
       bal_interface_los_data__init(&ifLosIndData);
-      balIndCfg.interface_los->data = &ifLosIndData; 
+      balIndCfg.interface_los->data = &ifLosIndData;
 
-      balIndCfg.interface_los->data->has_status = BAL_GRPC_PRES; 
-      balIndCfg.interface_los->data->status = int_los_ind->data.status; 
+      balIndCfg.interface_los->data->has_status = BAL_GRPC_PRES;
+      balIndCfg.interface_los->data->status = int_los_ind->data.status;
 
       BalErr *output;
       result = bal_ind__bal_iface_los(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -676,7 +707,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_interface_indication_cb                        * 
+ * Function    : bal_interface_indication_cb                        *
  * Description : This function will handle the indications for      *
  *               Interface Indication                           *
  *                                                                  *
@@ -685,7 +716,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_INTERFACE != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_INTERFACE != obj->obj_type ||
       bcmbal_interface_auto_id_ind != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -716,39 +747,39 @@
       bal_obj__init(&hdr);
       balIndCfg.interface_ind->hdr = &hdr;
 
-      BalInterfaceKey ifkey; 
+      BalInterfaceKey ifkey;
       memset(&ifkey, 0, sizeof(BalInterfaceKey));
       bal_interface_key__init(&ifkey);
-      balIndCfg.interface_ind->key = &ifkey; 
+      balIndCfg.interface_ind->key = &ifkey;
 
-      balIndCfg.interface_ind->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->key->intf_id = interface_ind->key.intf_id; 
-      balIndCfg.interface_ind->key->has_intf_type = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->key->intf_type = interface_ind->key.intf_type; 
-      
+      balIndCfg.interface_ind->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->key->intf_id = interface_ind->key.intf_id;
+      balIndCfg.interface_ind->key->has_intf_type = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->key->intf_type = interface_ind->key.intf_type;
+
       BalInterfaceIndData ifIndData;
       memset(&ifIndData, 0, sizeof(BalInterfaceIndData));
       bal_interface_ind_data__init(&ifIndData);
-      balIndCfg.interface_ind->data = &ifIndData; 
+      balIndCfg.interface_ind->data = &ifIndData;
 
-      balIndCfg.interface_ind->data->has_admin_state = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->admin_state = interface_ind->data.admin_state; 
-      balIndCfg.interface_ind->data->has_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->oper_status = interface_ind->data.oper_status; 
-      balIndCfg.interface_ind->data->has_min_data_agg_port_id = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->min_data_agg_port_id = interface_ind->data.min_data_agg_port_id; 
-      balIndCfg.interface_ind->data->has_min_data_svc_port_id = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->min_data_svc_port_id = interface_ind->data.min_data_svc_port_id; 
-      balIndCfg.interface_ind->data->has_transceiver_type = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->transceiver_type = interface_ind->data.transceiver_type; 
-      balIndCfg.interface_ind->data->has_ds_miss_mode = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->ds_miss_mode = interface_ind->data.ds_miss_mode; 
-      balIndCfg.interface_ind->data->has_mtu = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->mtu = interface_ind->data.mtu; 
-      balIndCfg.interface_ind->data->has_flow_control = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->flow_control = interface_ind->data.flow_control; 
-      balIndCfg.interface_ind->data->has_ds_tm = BAL_GRPC_PRES; 
-      balIndCfg.interface_ind->data->ds_tm = interface_ind->data.ds_tm; 
+      balIndCfg.interface_ind->data->has_admin_state = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->admin_state = interface_ind->data.admin_state;
+      balIndCfg.interface_ind->data->has_oper_status = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->oper_status = interface_ind->data.oper_status;
+      balIndCfg.interface_ind->data->has_min_data_agg_port_id = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->min_data_agg_port_id = interface_ind->data.min_data_agg_port_id;
+      balIndCfg.interface_ind->data->has_min_data_svc_port_id = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->min_data_svc_port_id = interface_ind->data.min_data_svc_port_id;
+      balIndCfg.interface_ind->data->has_transceiver_type = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->transceiver_type = interface_ind->data.transceiver_type;
+      balIndCfg.interface_ind->data->has_ds_miss_mode = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->ds_miss_mode = interface_ind->data.ds_miss_mode;
+      balIndCfg.interface_ind->data->has_mtu = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->mtu = interface_ind->data.mtu;
+      balIndCfg.interface_ind->data->has_flow_control = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->flow_control = interface_ind->data.flow_control;
+      balIndCfg.interface_ind->data->has_ds_tm = BAL_GRPC_PRES;
+      balIndCfg.interface_ind->data->ds_tm = interface_ind->data.ds_tm;
       balIndCfg.interface_ind->data->has_us_tm = BAL_GRPC_PRES;
       balIndCfg.interface_ind->data->us_tm = interface_ind->data.us_tm;
 
@@ -758,6 +789,8 @@
       balIndCfg.interface_ind->data->sub_term_id_list = &balFlows;
 
       balIndCfg.interface_ind->data->sub_term_id_list->n_val =  interface_ind->data.sub_term_id_list.len;
+      balIndCfg.interface_ind->data->sub_term_id_list->val =
+           (uint32_t *)malloc((balIndCfg.interface_ind->data->sub_term_id_list->n_val)*sizeof(uint32_t));
       memcpy(balIndCfg.interface_ind->data->sub_term_id_list->val, interface_ind->data.sub_term_id_list.val,
              balIndCfg.interface_ind->data->sub_term_id_list->n_val);
 
@@ -769,7 +802,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_sub_term_osc_indication_cb                     * 
+ * Function    : bal_sub_term_osc_indication_cb                     *
  * Description : This function will handle the indications for      *
  *               Subscriber term Operational State Change           *
  *                                                                  *
@@ -778,7 +811,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type ||
       bcmbal_subscriber_terminal_auto_id_oper_status_change != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -797,7 +830,7 @@
       balIndCfg.sub_group = obj->subgroup;
       balIndCfg.device_id = voltha_device_id;
 
-      bcmbal_subscriber_terminal_oper_status_change *sub_osc_ind = 
+      bcmbal_subscriber_terminal_oper_status_change *sub_osc_ind =
                            (bcmbal_subscriber_terminal_oper_status_change *)obj;
 
       BalSubscriberTerminalOperStatusChange subOscInd;
@@ -805,30 +838,35 @@
       bal_subscriber_terminal_oper_status_change__init(&subOscInd);
       balIndCfg.terminal_op_state = &subOscInd;
 
-      BalSubscriberTerminalKey subkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.terminal_op_state->hdr = &hdr;
+
+      BalSubscriberTerminalKey subkey;
       memset(&subkey, 0, sizeof(BalSubscriberTerminalKey));
       bal_subscriber_terminal_key__init(&subkey);
-      balIndCfg.terminal_op_state->key = &subkey; 
+      balIndCfg.terminal_op_state->key = &subkey;
 
-      balIndCfg.terminal_op_state->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_op_state->key->intf_id = sub_osc_ind->key.intf_id; 
-      balIndCfg.terminal_op_state->key->has_sub_term_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_op_state->key->sub_term_id = sub_osc_ind->key.sub_term_id; 
-      
+      balIndCfg.terminal_op_state->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_op_state->key->intf_id = sub_osc_ind->key.intf_id;
+      balIndCfg.terminal_op_state->key->has_sub_term_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_op_state->key->sub_term_id = sub_osc_ind->key.sub_term_id;
+
       BalSubscriberTerminalOperStatusChangeData subOscIndData;
       memset(&subOscIndData, 0, sizeof(BalSubscriberTerminalOperStatusChangeData));
       bal_subscriber_terminal_oper_status_change_data__init(&subOscIndData);
-      balIndCfg.terminal_op_state->data = &subOscIndData; 
+      balIndCfg.terminal_op_state->data = &subOscIndData;
 
-      balIndCfg.terminal_op_state->data->has_new_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.terminal_op_state->data->new_oper_status = 
-                                           sub_osc_ind->data.new_oper_status; 
-      balIndCfg.terminal_op_state->data->has_old_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.terminal_op_state->data->old_oper_status = 
-                                           sub_osc_ind->data.old_oper_status; 
-      balIndCfg.terminal_op_state->data->has_admin_state = BAL_GRPC_PRES; 
-      balIndCfg.terminal_op_state->data->admin_state = 
-                                               sub_osc_ind->data.admin_state; 
+      balIndCfg.terminal_op_state->data->has_new_oper_status = BAL_GRPC_PRES;
+      balIndCfg.terminal_op_state->data->new_oper_status =
+                                           sub_osc_ind->data.new_oper_status;
+      balIndCfg.terminal_op_state->data->has_old_oper_status = BAL_GRPC_PRES;
+      balIndCfg.terminal_op_state->data->old_oper_status =
+                                           sub_osc_ind->data.old_oper_status;
+      balIndCfg.terminal_op_state->data->has_admin_state = BAL_GRPC_PRES;
+      balIndCfg.terminal_op_state->data->admin_state =
+                                               sub_osc_ind->data.admin_state;
 
       BalErr *output;
       result = bal_ind__bal_subs_term_oper_sts_cng(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -838,7 +876,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_sub_term_disc_indication_cb                    * 
+ * Function    : bal_sub_term_disc_indication_cb                    *
  * Description : This function will handle the indications for      *
  *               Subscriber term disc indication                    *
  *                                                                  *
@@ -847,7 +885,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type ||
       bcmbal_subscriber_terminal_auto_id_sub_term_disc != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -868,7 +906,7 @@
       balIndCfg.sub_group = obj->subgroup;
       balIndCfg.device_id = voltha_device_id;
 
-      bcmbal_subscriber_terminal_sub_term_disc *sub_disc_ind = 
+      bcmbal_subscriber_terminal_sub_term_disc *sub_disc_ind =
                            (bcmbal_subscriber_terminal_sub_term_disc *)obj;
 
       BalSubscriberTerminalSubTermDisc subDiscInd;
@@ -881,20 +919,20 @@
       bal_obj__init(&hdr);
       balIndCfg.terminal_disc->hdr = &hdr;
 
-      BalSubscriberTerminalKey subkey; 
+      BalSubscriberTerminalKey subkey;
       memset(&subkey, 0, sizeof(BalSubscriberTerminalKey));
       bal_subscriber_terminal_key__init(&subkey);
-      balIndCfg.terminal_disc->key = &subkey; 
+      balIndCfg.terminal_disc->key = &subkey;
 
-      balIndCfg.terminal_disc->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_disc->key->intf_id = sub_disc_ind->key.intf_id; 
-      balIndCfg.terminal_disc->key->has_sub_term_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_disc->key->sub_term_id = sub_disc_ind->key.sub_term_id; 
-      
+      balIndCfg.terminal_disc->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_disc->key->intf_id = sub_disc_ind->key.intf_id;
+      balIndCfg.terminal_disc->key->has_sub_term_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_disc->key->sub_term_id = sub_disc_ind->key.sub_term_id;
+
       BalSubscriberTerminalSubTermDiscData subDiscIndData;
       memset(&subDiscIndData, 0, sizeof(BalSubscriberTerminalSubTermDiscData));
       bal_subscriber_terminal_sub_term_disc_data__init(&subDiscIndData);
-      balIndCfg.terminal_disc->data = &subDiscIndData; 
+      balIndCfg.terminal_disc->data = &subDiscIndData;
 
       BalSerialNumber serial_number;
       memset(&serial_number, 0, sizeof(BalSerialNumber));
@@ -927,7 +965,7 @@
 		      sub_disc_ind->data.serial_number.vendor_id[1],
 		      sub_disc_ind->data.serial_number.vendor_id[2],
 		      sub_disc_ind->data.serial_number.vendor_id[3]);
-      balIndCfg.terminal_disc->data->serial_number->vendor_id = vendor_id; 
+      balIndCfg.terminal_disc->data->serial_number->vendor_id = vendor_id;
       ASFVOLT_LOG(ASFVOLT_DEBUG, "ONU Discovery:After decoding:Vendor id is %s\n", balIndCfg.terminal_disc->data->serial_number->vendor_id);
       char vendor_specific[MAX_CHAR_LENGTH];
       memset(&vendor_specific, 0, MAX_CHAR_LENGTH);
@@ -942,7 +980,7 @@
 		      sub_disc_ind->data.serial_number.vendor_specific[3] & 0x0f);
       balIndCfg.terminal_disc->data->serial_number->vendor_specific = vendor_specific;
       ASFVOLT_LOG(ASFVOLT_DEBUG, "ONU Discovery:After decoding:Vendor specific is %s\n", balIndCfg.terminal_disc->data->serial_number->vendor_specific);
-       
+
       BalErr *output;
       result = bal_ind__bal_subs_term_discovery_ind(client, NULL, &balIndCfg, &output, NULL, 0);
    }
@@ -951,7 +989,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_sub_term_alarm_indication_cb                   * 
+ * Function    : bal_sub_term_alarm_indication_cb                   *
  * Description : This function will handle the indications for      *
  *               Subscriber term alarm indication                   *
  *                                                                  *
@@ -960,7 +998,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type ||
       bcmbal_subscriber_terminal_auto_id_sub_term_alarm != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -972,14 +1010,15 @@
       BalIndications balIndCfg;
       memset(&balIndCfg, 0, sizeof(BalIndications));
       bal_indications__init(&balIndCfg);
-      balIndCfg.u_case = BAL_INDICATIONS__U_TERMINAL_ALARM;
       balIndCfg.has_objtype = BAL_GRPC_PRES;
-      balIndCfg.objtype = obj->obj_type;
+      balIndCfg.objtype = BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL;
       balIndCfg.has_sub_group = BAL_GRPC_PRES;
       balIndCfg.sub_group = obj->subgroup;
+
       balIndCfg.device_id = voltha_device_id;
 
-      bcmbal_subscriber_terminal_sub_term_alarm *sub_term_alarm  = 
+      balIndCfg.u_case = BAL_INDICATIONS__U_TERMINAL_ALARM;
+      bcmbal_subscriber_terminal_sub_term_alarm *sub_term_alarm  =
                            (bcmbal_subscriber_terminal_sub_term_alarm *)obj;
 
       BalSubscriberTerminalSubTermAlarm subTermAlarm;
@@ -992,34 +1031,34 @@
       bal_obj__init(&hdr);
       balIndCfg.terminal_alarm->hdr = &hdr;
 
-      BalSubscriberTerminalKey subkey; 
+      BalSubscriberTerminalKey subkey;
       memset(&subkey, 0, sizeof(BalSubscriberTerminalKey));
       bal_subscriber_terminal_key__init(&subkey);
-      balIndCfg.terminal_alarm->key = &subkey; 
+      balIndCfg.terminal_alarm->key = &subkey;
 
-      balIndCfg.terminal_alarm->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_alarm->key->intf_id = sub_term_alarm->key.intf_id; 
-      balIndCfg.terminal_alarm->key->has_sub_term_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_alarm->key->sub_term_id = sub_term_alarm->key.sub_term_id; 
-      
+      balIndCfg.terminal_alarm->key->has_sub_term_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_alarm->key->sub_term_id = sub_term_alarm->key.sub_term_id;
+      balIndCfg.terminal_alarm->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_alarm->key->intf_id = sub_term_alarm->key.intf_id;
+
       BalsubscriberTerminalSubTermAlarmData subTermAlarmData;
       memset(&subTermAlarmData, 0, sizeof(BalsubscriberTerminalSubTermAlarmData));
       balsubscriber_terminal_sub_term_alarm_data__init(&subTermAlarmData);
-      balIndCfg.terminal_alarm->data = &subTermAlarmData; 
+      balIndCfg.terminal_alarm->data = &subTermAlarmData;
 
       BalSubscriberTerminalAlarms balSubAlarms;
       memset(&balSubAlarms, 0, sizeof(BalSubscriberTerminalAlarms));
       bal_subscriber_terminal_alarms__init(&balSubAlarms);
-      balIndCfg.terminal_alarm->data->alarm = &balSubAlarms; 
+      balIndCfg.terminal_alarm->data->alarm = &balSubAlarms;
 
-      balIndCfg.terminal_alarm->data->alarm->has_los = BAL_GRPC_PRES; 
-      balIndCfg.terminal_alarm->data->alarm->los = sub_term_alarm->data.alarm.los; 
-      balIndCfg.terminal_alarm->data->alarm->has_lob = BAL_GRPC_PRES; 
-      balIndCfg.terminal_alarm->data->alarm->lob = sub_term_alarm->data.alarm.lob; 
-      balIndCfg.terminal_alarm->data->alarm->has_lopc_miss = BAL_GRPC_PRES; 
-      balIndCfg.terminal_alarm->data->alarm->lopc_miss = sub_term_alarm->data.alarm.lopc_miss; 
-      balIndCfg.terminal_alarm->data->alarm->has_lopc_mic_error = BAL_GRPC_PRES; 
-      balIndCfg.terminal_alarm->data->alarm->lopc_mic_error = sub_term_alarm->data.alarm.lopc_mic_error; 
+      balIndCfg.terminal_alarm->data->alarm->has_los = BAL_GRPC_PRES;
+      balIndCfg.terminal_alarm->data->alarm->los = sub_term_alarm->data.alarm.los;
+      balIndCfg.terminal_alarm->data->alarm->has_lob = BAL_GRPC_PRES;
+      balIndCfg.terminal_alarm->data->alarm->lob = sub_term_alarm->data.alarm.lob;
+      balIndCfg.terminal_alarm->data->alarm->has_lopc_miss = BAL_GRPC_PRES;
+      balIndCfg.terminal_alarm->data->alarm->lopc_miss = sub_term_alarm->data.alarm.lopc_miss;
+      balIndCfg.terminal_alarm->data->alarm->has_lopc_mic_error = BAL_GRPC_PRES;
+      balIndCfg.terminal_alarm->data->alarm->lopc_mic_error = sub_term_alarm->data.alarm.lopc_mic_error;
 
       BalErr *output;
       result = bal_ind__bal_subs_term_alarm_ind(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -1029,7 +1068,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_sub_term_dgi_indication_cb                     * 
+ * Function    : bal_sub_term_dgi_indication_cb                     *
  * Description : This function will handle the indications for      *
  *               Subscriber term dgi indication                     *
  *                                                                  *
@@ -1038,7 +1077,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type ||
       bcmbal_subscriber_terminal_auto_id_dgi != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -1057,7 +1096,7 @@
       balIndCfg.sub_group = obj->subgroup;
       balIndCfg.device_id = voltha_device_id;
 
-      bcmbal_subscriber_terminal_dgi *sub_dgi_ind = 
+      bcmbal_subscriber_terminal_dgi *sub_dgi_ind =
                            (bcmbal_subscriber_terminal_dgi *)obj;
 
       BalSubscriberTerminalDgi subDgiInd;
@@ -1065,20 +1104,25 @@
       bal_subscriber_terminal_dgi__init(&subDgiInd);
       balIndCfg.terminal_dgi= &subDgiInd;
 
-      BalSubscriberTerminalKey subkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.terminal_dgi->hdr = &hdr;
+
+      BalSubscriberTerminalKey subkey;
       memset(&subkey, 0, sizeof(BalSubscriberTerminalKey));
       bal_subscriber_terminal_key__init(&subkey);
-      balIndCfg.terminal_disc->key = &subkey; 
+      balIndCfg.terminal_disc->key = &subkey;
 
-      balIndCfg.terminal_dgi->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_dgi->key->intf_id = sub_dgi_ind->key.intf_id; 
-      balIndCfg.terminal_dgi->key->has_sub_term_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_dgi->key->sub_term_id = sub_dgi_ind->key.sub_term_id; 
-      
+      balIndCfg.terminal_dgi->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_dgi->key->intf_id = sub_dgi_ind->key.intf_id;
+      balIndCfg.terminal_dgi->key->has_sub_term_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_dgi->key->sub_term_id = sub_dgi_ind->key.sub_term_id;
+
       BalSubscriberTerminalDgiData subDgiIndData;
       memset(&subDgiIndData, 0, sizeof(BalSubscriberTerminalDgiData));
       bal_subscriber_terminal_dgi_data__init(&subDgiIndData);
-      balIndCfg.terminal_dgi->data = &subDgiIndData; 
+      balIndCfg.terminal_dgi->data = &subDgiIndData;
 
       balIndCfg.terminal_dgi->data->has_dgi_status = BAL_GRPC_PRES;
       balIndCfg.terminal_dgi->data->dgi_status = sub_dgi_ind->data.dgi_status;
@@ -1091,7 +1135,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_sub_term_indication_cb                         * 
+ * Function    : bal_sub_term_indication_cb                         *
  * Description : This function will handle the indications for      *
  *               Subscriber term indication                         *
  *                                                                  *
@@ -1100,7 +1144,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL != obj->obj_type ||
       bcmbal_subscriber_terminal_auto_id_ind != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -1131,33 +1175,33 @@
       bal_obj__init(&hdr);
       balIndCfg.terminal_ind->hdr = &hdr;
 
-      BalSubscriberTerminalKey subkey; 
+      BalSubscriberTerminalKey subkey;
       memset(&subkey, 0, sizeof(BalSubscriberTerminalKey));
       bal_subscriber_terminal_key__init(&subkey);
-      balIndCfg.terminal_ind->key = &subkey; 
+      balIndCfg.terminal_ind->key = &subkey;
 
-      balIndCfg.terminal_ind->key->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->key->intf_id = sub_ind->key.intf_id; 
-      balIndCfg.terminal_ind->key->has_sub_term_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->key->sub_term_id = sub_ind->key.sub_term_id; 
-      
+      balIndCfg.terminal_ind->key->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->key->intf_id = sub_ind->key.intf_id;
+      balIndCfg.terminal_ind->key->has_sub_term_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->key->sub_term_id = sub_ind->key.sub_term_id;
+
       BalSubscriberTerminalIndData subIndData;
       memset(&subIndData, 0, sizeof(BalSubscriberTerminalIndData));
       bal_subscriber_terminal_ind_data__init(&subIndData);
-      balIndCfg.terminal_ind->data = &subIndData; 
+      balIndCfg.terminal_ind->data = &subIndData;
 
-      balIndCfg.terminal_ind->data->has_admin_state = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->data->admin_state = sub_ind->data.admin_state; 
-      balIndCfg.terminal_ind->data->has_oper_status = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->data->oper_status = sub_ind->data.oper_status; 
-      balIndCfg.terminal_ind->data->has_svc_port_id = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->data->svc_port_id = sub_ind->data.svc_port_id; 
-      balIndCfg.terminal_ind->data->has_ds_tm = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->data->ds_tm = sub_ind->data.ds_tm; 
-      balIndCfg.terminal_ind->data->has_us_tm = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->data->us_tm = sub_ind->data.us_tm; 
-      balIndCfg.terminal_ind->data->has_sub_term_rate = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->data->sub_term_rate = sub_ind->data.sub_term_rate; 
+      balIndCfg.terminal_ind->data->has_admin_state = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->data->admin_state = sub_ind->data.admin_state;
+      balIndCfg.terminal_ind->data->has_oper_status = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->data->oper_status = sub_ind->data.oper_status;
+      balIndCfg.terminal_ind->data->has_svc_port_id = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->data->svc_port_id = sub_ind->data.svc_port_id;
+      balIndCfg.terminal_ind->data->has_ds_tm = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->data->ds_tm = sub_ind->data.ds_tm;
+      balIndCfg.terminal_ind->data->has_us_tm = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->data->us_tm = sub_ind->data.us_tm;
+      balIndCfg.terminal_ind->data->has_sub_term_rate = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->data->sub_term_rate = sub_ind->data.sub_term_rate;
       char password[MAX_CHAR_LENGTH*2];
       memset(&password, 0, MAX_CHAR_LENGTH*2);
       strcpy(password,(const char *)sub_ind->data.password.arr);
@@ -1166,14 +1210,14 @@
       memset(&registration_id, 0, MAX_CHAR_LENGTH*8);
       strcpy(registration_id,(const char *)sub_ind->data.registration_id.arr);
       balIndCfg.terminal_ind->data->registration_id =  registration_id;
-    
-#if 0 
-      balIndCfg.terminal_ind->data->has_mac_address = BAL_GRPC_PRES; 
-      balIndCfg.terminal_ind->data->mac_address.len = 
+
+#if 0
+      balIndCfg.terminal_ind->data->has_mac_address = BAL_GRPC_PRES;
+      balIndCfg.terminal_ind->data->mac_address.len =
                             (BCMOS_ETH_ALEN)*sizeof(sub_ind->data.mac_address.u8);
       uint8_t mac_address[balIndCfg.terminal_ind->data->mac_address.len];
       memset(&mac_address, 0 ,balIndCfg.terminal_ind->data->mac_address.len);
-      strcpy((char *)mac_address,(const char *)sub_ind->data.mac_address.u8); 
+      strcpy((char *)mac_address,(const char *)sub_ind->data.mac_address.u8);
       balIndCfg.terminal_ind->data->mac_address.data = mac_address;
 #endif
 
@@ -1192,7 +1236,7 @@
 		      sub_ind->data.serial_number.vendor_id[1],
 		      sub_ind->data.serial_number.vendor_id[2],
 		      sub_ind->data.serial_number.vendor_id[3]);
-      balIndCfg.terminal_ind->data->serial_number->vendor_id = vendor_id; 
+      balIndCfg.terminal_ind->data->serial_number->vendor_id = vendor_id;
       ASFVOLT_LOG(ASFVOLT_ERROR, "ONU Activation:After decoding:Vendor id is %s\n", balIndCfg.terminal_ind->data->serial_number->vendor_id);
       char vendor_specific[MAX_CHAR_LENGTH];
       memset(&vendor_specific, 0, MAX_CHAR_LENGTH);
@@ -1229,24 +1273,24 @@
 }
 
 /********************************************************************\
- * Function    : fill_bal_tm_red                                    * 
+ * Function    : fill_bal_tm_red                                    *
  * Description : This function will fill grpc-BalTmred struture     *
  *               from bal-bcmbal_tm_red structure                   *
  *                                                                  *
  ********************************************************************/
 void fill_bal_tm_red(BalTmred *grpc_red, bcmbal_tm_red *bal_red)
 {
-   grpc_red->has_min_threshold = BAL_GRPC_PRES; 
-   grpc_red->min_threshold = bal_red->min_threshold; 
-   grpc_red->has_max_threshold = BAL_GRPC_PRES; 
-   grpc_red->max_threshold = bal_red->max_threshold; 
-   grpc_red->has_max_probability = BAL_GRPC_PRES; 
+   grpc_red->has_min_threshold = BAL_GRPC_PRES;
+   grpc_red->min_threshold = bal_red->min_threshold;
+   grpc_red->has_max_threshold = BAL_GRPC_PRES;
+   grpc_red->max_threshold = bal_red->max_threshold;
+   grpc_red->has_max_probability = BAL_GRPC_PRES;
    grpc_red->max_probability = bal_red->max_probability;
-   return; 
-} 
+   return;
+}
 
 /********************************************************************\
- * Function    : bal_tm_queue_indication_cb                         * 
+ * Function    : bal_tm_queue_indication_cb                         *
  * Description : This function will handle the indications for      *
  *               TM Queue indication                                *
  *                                                                  *
@@ -1255,7 +1299,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_TM_QUEUE != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_TM_QUEUE != obj->obj_type ||
       bcmbal_tm_queue_auto_id_ind != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -1281,52 +1325,52 @@
       bal_tm_queue_ind__init(&tmQueInd);
       balIndCfg.tm_queue_ind = &tmQueInd;
 
-      BalTmQueueKey tmQkey; 
+      BalTmQueueKey tmQkey;
       memset(&tmQkey, 0, sizeof(BalTmQueueKey));
       bal_tm_queue_key__init(&tmQkey);
-      balIndCfg.tm_queue_ind->key = &tmQkey; 
+      balIndCfg.tm_queue_ind->key = &tmQkey;
 
-      balIndCfg.tm_queue_ind->key->has_sched_id = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->key->sched_id = tm_que_ind->key.sched_id; 
-      balIndCfg.tm_queue_ind->key->has_sched_dir = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->key->sched_dir = tm_que_ind->key.sched_dir; 
-      balIndCfg.tm_queue_ind->key->has_id = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->key->id = tm_que_ind->key.id; 
-      
+      balIndCfg.tm_queue_ind->key->has_sched_id = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->key->sched_id = tm_que_ind->key.sched_id;
+      balIndCfg.tm_queue_ind->key->has_sched_dir = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->key->sched_dir = tm_que_ind->key.sched_dir;
+      balIndCfg.tm_queue_ind->key->has_id = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->key->id = tm_que_ind->key.id;
+
       BalTmQueueIndData tmQIndData;
       memset(&tmQIndData, 0, sizeof(BalTmQueueIndData));
       bal_tm_queue_ind_data__init(&tmQIndData);
-      balIndCfg.tm_queue_ind->data = &tmQIndData; 
+      balIndCfg.tm_queue_ind->data = &tmQIndData;
 
-      balIndCfg.tm_queue_ind->data->has_priority = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->priority = tm_que_ind->data.priority; 
-      balIndCfg.tm_queue_ind->data->has_weight = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->weight = tm_que_ind->data.weight; 
-      balIndCfg.tm_queue_ind->data->has_create_mode = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->create_mode = tm_que_ind->data.create_mode; 
-      balIndCfg.tm_queue_ind->data->has_ref_count = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->ref_count = tm_que_ind->data.ref_count; 
+      balIndCfg.tm_queue_ind->data->has_priority = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->priority = tm_que_ind->data.priority;
+      balIndCfg.tm_queue_ind->data->has_weight = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->weight = tm_que_ind->data.weight;
+      balIndCfg.tm_queue_ind->data->has_create_mode = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->create_mode = tm_que_ind->data.create_mode;
+      balIndCfg.tm_queue_ind->data->has_ref_count = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->ref_count = tm_que_ind->data.ref_count;
 
       BalTmShaping balShape;
       memset(&balShape, 0, sizeof(BalTmShaping));
       bal_tm_shaping__init(&balShape);
-      balIndCfg.tm_queue_ind->data->rate = &balShape; 
+      balIndCfg.tm_queue_ind->data->rate = &balShape;
 
-      balIndCfg.tm_queue_ind->data->rate->has_presence_mask = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->rate->presence_mask = tm_que_ind->data.rate.presence_mask; 
-      balIndCfg.tm_queue_ind->data->rate->has_cir = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->rate->cir = tm_que_ind->data.rate.cir; 
-      balIndCfg.tm_queue_ind->data->rate->has_pir = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->rate->pir = tm_que_ind->data.rate.pir; 
-      balIndCfg.tm_queue_ind->data->rate->has_burst = BAL_GRPC_PRES; 
-      balIndCfg.tm_queue_ind->data->rate->burst = tm_que_ind->data.rate.burst; 
+      balIndCfg.tm_queue_ind->data->rate->has_presence_mask = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->rate->presence_mask = tm_que_ind->data.rate.presence_mask;
+      balIndCfg.tm_queue_ind->data->rate->has_cir = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->rate->cir = tm_que_ind->data.rate.cir;
+      balIndCfg.tm_queue_ind->data->rate->has_pir = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->rate->pir = tm_que_ind->data.rate.pir;
+      balIndCfg.tm_queue_ind->data->rate->has_burst = BAL_GRPC_PRES;
+      balIndCfg.tm_queue_ind->data->rate->burst = tm_que_ind->data.rate.burst;
 
       BalTmBac balBac;
       memset(&balBac, 0, sizeof(BalTmBac));
       bal_tm_bac__init(&balBac);
-      balIndCfg.tm_queue_ind->data->bac = &balBac; 
+      balIndCfg.tm_queue_ind->data->bac = &balBac;
 
-      balIndCfg.tm_queue_ind->data->bac->has_type = BAL_GRPC_PRES; 
+      balIndCfg.tm_queue_ind->data->bac->has_type = BAL_GRPC_PRES;
       balIndCfg.tm_queue_ind->data->bac->type = tm_que_ind->data.bac.type;
       switch(tm_que_ind->data.bac.type)
       {
@@ -1336,11 +1380,11 @@
             BalTMBacTaildrop balTaildrop;
             memset(&balTaildrop, 0, sizeof(BalTMBacTaildrop));
             bal_tmbac_taildrop__init(&balTaildrop);
-            balIndCfg.tm_queue_ind->data->bac->taildrop = &balTaildrop; 
+            balIndCfg.tm_queue_ind->data->bac->taildrop = &balTaildrop;
 
-            balIndCfg.tm_queue_ind->data->bac->taildrop->has_max_size = BAL_GRPC_PRES; 
-            balIndCfg.tm_queue_ind->data->bac->taildrop->max_size = 
-                                               tm_que_ind->data.bac.u.taildrop.max_size; 
+            balIndCfg.tm_queue_ind->data->bac->taildrop->has_max_size = BAL_GRPC_PRES;
+            balIndCfg.tm_queue_ind->data->bac->taildrop->max_size =
+                                               tm_que_ind->data.bac.u.taildrop.max_size;
          }
          break;
          case BCMBAL_TM_BAC_TYPE_WTAILDROP:
@@ -1354,12 +1398,12 @@
             BalTMBacRed balBacRed;
             memset(&balBacRed, 0, sizeof(BalTMBacRed));
             bal_tmbac_red__init(&balBacRed);
-            balIndCfg.tm_queue_ind->data->bac->red = &balBacRed; 
+            balIndCfg.tm_queue_ind->data->bac->red = &balBacRed;
 
             BalTmred balRed;
             memset(&balRed, 0, sizeof(BalTmred));
             bal_tmred__init(&balRed);
-            balIndCfg.tm_queue_ind->data->bac->red->red = &balRed; 
+            balIndCfg.tm_queue_ind->data->bac->red->red = &balRed;
             fill_bal_tm_red(balIndCfg.tm_queue_ind->data->bac->red->red, &tm_que_ind->data.bac.u.red.red);
          }
          break;
@@ -1369,24 +1413,24 @@
             BalTMBacWred balBacWred;
             memset(&balBacWred, 0, sizeof(BalTMBacWred));
             bal_tmbac_wred__init(&balBacWred);
-            balIndCfg.tm_queue_ind->data->bac->wred = &balBacWred; 
+            balIndCfg.tm_queue_ind->data->bac->wred = &balBacWred;
 
             BalTmred balGreen;
             memset(&balGreen, 0, sizeof(BalTmred));
             bal_tmred__init(&balGreen);
-            balIndCfg.tm_queue_ind->data->bac->wred->green = &balGreen; 
+            balIndCfg.tm_queue_ind->data->bac->wred->green = &balGreen;
             fill_bal_tm_red(balIndCfg.tm_queue_ind->data->bac->wred->green, &tm_que_ind->data.bac.u.wred.green);
 
             BalTmred balYellow;
             memset(&balYellow, 0, sizeof(BalTmred));
             bal_tmred__init(&balYellow);
-            balIndCfg.tm_queue_ind->data->bac->wred->yellow = &balYellow; 
+            balIndCfg.tm_queue_ind->data->bac->wred->yellow = &balYellow;
             fill_bal_tm_red(balIndCfg.tm_queue_ind->data->bac->wred->yellow, &tm_que_ind->data.bac.u.wred.yellow);
 
             BalTmred balRed;
             memset(&balRed, 0, sizeof(BalTmred));
             bal_tmred__init(&balRed);
-            balIndCfg.tm_queue_ind->data->bac->wred->red = &balRed; 
+            balIndCfg.tm_queue_ind->data->bac->wred->red = &balRed;
             fill_bal_tm_red(balIndCfg.tm_queue_ind->data->bac->wred->red, &tm_que_ind->data.bac.u.wred.red);
          }
          break;
@@ -1395,8 +1439,8 @@
             balIndCfg.tm_queue_ind->data->bac->u_case = BAL_TM_BAC__U__NOT_SET;
          }
          break;
-      
-      } 
+
+      }
 
       BalErr *output;
       result = bal_ind__bal_tm_queue_ind_info(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -1406,7 +1450,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_tm_sched_indication_cb                         * 
+ * Function    : bal_tm_sched_indication_cb                         *
  * Description : This function will handle the indications for      *
  *               TM Sched indication                                *
  *                                                                  *
@@ -1415,7 +1459,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_TM_SCHED != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_TM_SCHED != obj->obj_type ||
       bcmbal_tm_sched_auto_id_ind != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -1441,21 +1485,21 @@
       bal_tm_sched_ind__init(&tmSchedInd);
       balIndCfg.tm_sched_ind = &tmSchedInd;
 
-      BalTmSchedKey tmSchedkey; 
+      BalTmSchedKey tmSchedkey;
       memset(&tmSchedkey, 0, sizeof(BalTmSchedKey));
       bal_tm_sched_key__init(&tmSchedkey);
-      balIndCfg.tm_sched_ind->key = &tmSchedkey; 
+      balIndCfg.tm_sched_ind->key = &tmSchedkey;
 
-      balIndCfg.tm_sched_ind->key->has_dir = BAL_GRPC_PRES; 
-      balIndCfg.tm_sched_ind->key->dir = tm_sched_ind->key.dir; 
-      balIndCfg.tm_sched_ind->key->has_id = BAL_GRPC_PRES; 
-      balIndCfg.tm_sched_ind->key->id = tm_sched_ind->key.id; 
-      
+      balIndCfg.tm_sched_ind->key->has_dir = BAL_GRPC_PRES;
+      balIndCfg.tm_sched_ind->key->dir = tm_sched_ind->key.dir;
+      balIndCfg.tm_sched_ind->key->has_id = BAL_GRPC_PRES;
+      balIndCfg.tm_sched_ind->key->id = tm_sched_ind->key.id;
+
       BalTmSchedIndData tmSIndData;
       memset(&tmSIndData, 0, sizeof(BalTmSchedIndData));
       bal_tm_sched_ind_data__init(&tmSIndData);
       balIndCfg.tm_sched_ind->data = &tmSIndData;
-      /* TODO: data should be populate */ 
+      /* TODO: data should be populate */
 
       BalErr *output;
       result = bal_ind__bal_tm_sched_ind_info(client, NULL, &balIndCfg, &output, NULL, 0);
@@ -1465,7 +1509,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_packet_data_indication_cb                      * 
+ * Function    : bal_packet_data_indication_cb                      *
  * Description : This function will handle the indications for      *
  *               Packet Data indication                             *
  *                                                                  *
@@ -1474,7 +1518,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_PACKET != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_PACKET != obj->obj_type ||
       bcmbal_packet_auto_id_bearer_channel_rx != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -1500,16 +1544,21 @@
       bal_packet_bearer_channel_rx__init(&rxChannel);
       balIndCfg.pktdata = &rxChannel;
 
-      BalPacketKey packetkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.pktdata->hdr = &hdr;
+
+      BalPacketKey packetkey;
       memset(&packetkey, 0, sizeof(BalPacketKey));
       bal_packet_key__init(&packetkey);
-      balIndCfg.pktdata->key = &packetkey; 
+      balIndCfg.pktdata->key = &packetkey;
 
-      bcmbal_packet_bearer_channel_rx *rx_channel = 
+      bcmbal_packet_bearer_channel_rx *rx_channel =
                                   (bcmbal_packet_bearer_channel_rx *)obj;
 
-      balIndCfg.pktdata->key->has_reserved = BAL_GRPC_PRES; 
-      balIndCfg.pktdata->key->reserved = rx_channel->key.reserved; 
+      balIndCfg.pktdata->key->has_reserved = BAL_GRPC_PRES;
+      balIndCfg.pktdata->key->reserved = rx_channel->key.reserved;
 
       BalDest PktSndDest;
       memset(&PktSndDest, 0, sizeof(BalDest));
@@ -1517,7 +1566,7 @@
       balIndCfg.pktdata->key->packet_send_dest = &PktSndDest;
 
       balIndCfg.pktdata->key->packet_send_dest->has_type = BAL_GRPC_PRES;
-      balIndCfg.pktdata->key->packet_send_dest->type = 
+      balIndCfg.pktdata->key->packet_send_dest->type =
                                           rx_channel->key.packet_send_dest.type;
       switch( rx_channel->key.packet_send_dest.type)
       {
@@ -1529,7 +1578,7 @@
             bal_dest_nni__init(&balNni);
             balIndCfg.pktdata->key->packet_send_dest->nni = &balNni;
             balIndCfg.pktdata->key->packet_send_dest->nni->has_intf_id = BAL_GRPC_PRES;
-            balIndCfg.pktdata->key->packet_send_dest->nni->intf_id = 
+            balIndCfg.pktdata->key->packet_send_dest->nni->intf_id =
                                           rx_channel->key.packet_send_dest.u.nni.intf_id;
          }
          break;
@@ -1540,17 +1589,17 @@
             memset(&balSubTerm, 0, sizeof(BalDestSubTerm));
             bal_dest_sub_term__init(&balSubTerm);
             balIndCfg.pktdata->key->packet_send_dest->sub_term = &balSubTerm;
-            balIndCfg.pktdata->key->packet_send_dest->sub_term->has_sub_term_id = 
+            balIndCfg.pktdata->key->packet_send_dest->sub_term->has_sub_term_id =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.pktdata->key->packet_send_dest->sub_term->sub_term_id = 
+            balIndCfg.pktdata->key->packet_send_dest->sub_term->sub_term_id =
                                  rx_channel->key.packet_send_dest.u.sub_term.sub_term_id;
-            balIndCfg.pktdata->key->packet_send_dest->sub_term->has_sub_term_uni = 
+            balIndCfg.pktdata->key->packet_send_dest->sub_term->has_sub_term_uni =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.pktdata->key->packet_send_dest->sub_term->sub_term_uni = 
+            balIndCfg.pktdata->key->packet_send_dest->sub_term->sub_term_uni =
                                 rx_channel->key.packet_send_dest.u.sub_term.sub_term_uni;
-            balIndCfg.pktdata->key->packet_send_dest->sub_term->has_intf_id = 
+            balIndCfg.pktdata->key->packet_send_dest->sub_term->has_intf_id =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.pktdata->key->packet_send_dest->sub_term->intf_id = 
+            balIndCfg.pktdata->key->packet_send_dest->sub_term->intf_id =
                                       rx_channel->key.packet_send_dest.u.sub_term.intf_id;
          }
          break;
@@ -1561,13 +1610,13 @@
             memset(&balSvcPort, 0, sizeof(BalDestSvcPort));
             bal_dest_svc_port__init(&balSvcPort);
             balIndCfg.pktdata->key->packet_send_dest->svc_port = &balSvcPort;
-            balIndCfg.pktdata->key->packet_send_dest->svc_port->has_svc_port_id = 
+            balIndCfg.pktdata->key->packet_send_dest->svc_port->has_svc_port_id =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.pktdata->key->packet_send_dest->svc_port->svc_port_id = 
+            balIndCfg.pktdata->key->packet_send_dest->svc_port->svc_port_id =
                                  rx_channel->key.packet_send_dest.u.svc_port.svc_port_id;
-            balIndCfg.pktdata->key->packet_send_dest->svc_port->has_intf_id = 
+            balIndCfg.pktdata->key->packet_send_dest->svc_port->has_intf_id =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.pktdata->key->packet_send_dest->svc_port->has_intf_id = 
+            balIndCfg.pktdata->key->packet_send_dest->svc_port->has_intf_id =
                                       rx_channel->key.packet_send_dest.u.svc_port.intf_id;
          }
          break;
@@ -1581,24 +1630,24 @@
       BalPacketBearerChannelRxData pkdData;
       memset(&pkdData, 0, sizeof(BalPacketBearerChannelRxData));
       bal_packet_bearer_channel_rx_data__init(&pkdData);
-      balIndCfg.pktdata->data = &pkdData; 
+      balIndCfg.pktdata->data = &pkdData;
 
-      balIndCfg.pktdata->data->has_flow_id = BAL_GRPC_PRES; 
-      balIndCfg.pktdata->data->flow_id = rx_channel->data.flow_id; 
-      balIndCfg.pktdata->data->has_flow_type = BAL_GRPC_PRES; 
-      balIndCfg.pktdata->data->flow_type = rx_channel->data.flow_type; 
-      balIndCfg.pktdata->data->has_intf_id = BAL_GRPC_PRES; 
-      balIndCfg.pktdata->data->intf_id = rx_channel->data.intf_id; 
-      balIndCfg.pktdata->data->has_intf_type = BAL_GRPC_PRES; 
-      balIndCfg.pktdata->data->intf_type = rx_channel->data.intf_type; 
-      balIndCfg.pktdata->data->has_svc_port = BAL_GRPC_PRES; 
-      balIndCfg.pktdata->data->svc_port = rx_channel->data.svc_port; 
-      balIndCfg.pktdata->data->has_flow_cookie = BAL_GRPC_PRES; 
-      balIndCfg.pktdata->data->flow_cookie = rx_channel->data.flow_cookie; 
-      balIndCfg.pktdata->data->has_pkt = BAL_GRPC_PRES; 
+      balIndCfg.pktdata->data->has_flow_id = BAL_GRPC_PRES;
+      balIndCfg.pktdata->data->flow_id = rx_channel->data.flow_id;
+      balIndCfg.pktdata->data->has_flow_type = BAL_GRPC_PRES;
+      balIndCfg.pktdata->data->flow_type = rx_channel->data.flow_type;
+      balIndCfg.pktdata->data->has_intf_id = BAL_GRPC_PRES;
+      balIndCfg.pktdata->data->intf_id = rx_channel->data.intf_id;
+      balIndCfg.pktdata->data->has_intf_type = BAL_GRPC_PRES;
+      balIndCfg.pktdata->data->intf_type = rx_channel->data.intf_type;
+      balIndCfg.pktdata->data->has_svc_port = BAL_GRPC_PRES;
+      balIndCfg.pktdata->data->svc_port = rx_channel->data.svc_port;
+      balIndCfg.pktdata->data->has_flow_cookie = BAL_GRPC_PRES;
+      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); 
+      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*/
 
@@ -1610,7 +1659,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_omci_data_indication_cb                        * 
+ * Function    : bal_omci_data_indication_cb                        *
  * Description : This function will handle the indications for      *
  *               OMCI Data Response                                 *
  *                                                                  *
@@ -1619,7 +1668,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_PACKET != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_PACKET != obj->obj_type ||
       bcmbal_packet_auto_id_itu_omci_channel_rx != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -1644,27 +1693,32 @@
       bal_packet_itu_omci_channel_rx__init(&omciChannel);
       balIndCfg.balomciresp = &omciChannel;
 
-      BalPacketKey packetkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.balomciresp->hdr = &hdr;
+
+      BalPacketKey packetkey;
       memset(&packetkey, 0, sizeof(BalPacketKey));
       bal_packet_key__init(&packetkey);
-      balIndCfg.balomciresp->key = &packetkey; 
+      balIndCfg.balomciresp->key = &packetkey;
 
       BalPacketItuOmciChannelRxData omciData;
       memset(&omciData, 0, sizeof(BalPacketItuOmciChannelRxData));
       bal_packet_itu_omci_channel_rx_data__init(&omciData);
-      balIndCfg.balomciresp->data = &omciData; 
-      
-      bcmbal_packet_itu_omci_channel_rx *omci_channel = 
+      balIndCfg.balomciresp->data = &omciData;
+
+      bcmbal_packet_itu_omci_channel_rx *omci_channel =
                                   (bcmbal_packet_itu_omci_channel_rx *)obj;
 
       balIndCfg.balomciresp->data->has_pkt =  BAL_GRPC_PRES;
       balIndCfg.balomciresp->data->pkt.len =  omci_channel->data.pkt.len;
-      balIndCfg.balomciresp->data->pkt.data = (uint8_t *)malloc((omci_channel->data.pkt.len)*sizeof(uint8_t)); 
+      balIndCfg.balomciresp->data->pkt.data = (uint8_t *)malloc((omci_channel->data.pkt.len)*sizeof(uint8_t));
       memcpy(balIndCfg.balomciresp->data->pkt.data, omci_channel->data.pkt.val,
              balIndCfg.balomciresp->data->pkt.len);
 
-      balIndCfg.balomciresp->key->has_reserved = BAL_GRPC_PRES; 
-      balIndCfg.balomciresp->key->reserved = omci_channel->key.reserved; 
+      balIndCfg.balomciresp->key->has_reserved = BAL_GRPC_PRES;
+      balIndCfg.balomciresp->key->reserved = omci_channel->key.reserved;
 
       BalDest PktSndDest;
       memset(&PktSndDest, 0, sizeof(BalDest));
@@ -1672,7 +1726,7 @@
       balIndCfg.balomciresp->key->packet_send_dest = &PktSndDest;
 
       balIndCfg.balomciresp->key->packet_send_dest->has_type = BAL_GRPC_PRES;
-      balIndCfg.balomciresp->key->packet_send_dest->type = 
+      balIndCfg.balomciresp->key->packet_send_dest->type =
                                           omci_channel->key.packet_send_dest.type;
       switch( omci_channel->key.packet_send_dest.type)
       {
@@ -1683,16 +1737,16 @@
             memset(&balOmci, 0, sizeof(BalItuOmciChannel));
             bal_itu_omci_channel__init(&balOmci);
             balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel = &balOmci;
-            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->has_sub_term_id = 
+            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->has_sub_term_id =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->sub_term_id = 
+            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->sub_term_id =
                             omci_channel->key.packet_send_dest.u.itu_omci_channel.sub_term_id;
-            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->has_intf_id = 
+            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->has_intf_id =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->intf_id = 
+            balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->intf_id =
                                  omci_channel->key.packet_send_dest.u.itu_omci_channel.intf_id;
             ASFVOLT_LOG(ASFVOLT_DEBUG, "OMCI Response for ONU id %d\n",
-                 balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->sub_term_id); 
+                 balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->sub_term_id);
          }
          break;
          default:
@@ -1710,7 +1764,7 @@
       }
       printf("\n");
       ASFVOLT_LOG(ASFVOLT_DEBUG, "OMCI Response for ONU id %d\n",
-		      balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->sub_term_id); 
+		      balIndCfg.balomciresp->key->packet_send_dest->itu_omci_channel->sub_term_id);
       BalErr *output;
       result = bal_ind__bal_pkt_omci_channel_rx_ind(client, NULL, &balIndCfg, &output, NULL, 0);
    }
@@ -1719,7 +1773,7 @@
 }
 
 /********************************************************************\
- * Function    : bal_oam_data_indication_cb                         * 
+ * Function    : bal_oam_data_indication_cb                         *
  * Description : This function will handle the indications for      *
  *               OAM Data Response                                 *
  *                                                                  *
@@ -1728,7 +1782,7 @@
 {
    bcmos_errno result = BCM_ERR_OK;
 
-   if(BCMBAL_OBJ_ID_PACKET != obj->obj_type || 
+   if(BCMBAL_OBJ_ID_PACKET != obj->obj_type ||
       bcmbal_packet_auto_id_ieee_oam_channel_rx != obj->subgroup)
    {
       ASFVOLT_LOG(ASFVOLT_ERROR, "Processing BAL API \'%s\' IND callback (status is %s)\n",
@@ -1752,16 +1806,21 @@
       bal_packet_ieee_oam_channel_rx__init(&oamChannel);
       balIndCfg.baloamresp = &oamChannel;
 
-      BalPacketKey packetkey; 
+      BalObj hdr;
+      memset(&hdr, 0, sizeof(BalObj));
+      bal_obj__init(&hdr);
+      balIndCfg.baloamresp->hdr = &hdr;
+
+      BalPacketKey packetkey;
       memset(&packetkey, 0, sizeof(BalPacketKey));
       bal_packet_key__init(&packetkey);
-      balIndCfg.baloamresp->key = &packetkey; 
+      balIndCfg.baloamresp->key = &packetkey;
 
-      bcmbal_packet_ieee_oam_channel_rx *oam_channel = 
+      bcmbal_packet_ieee_oam_channel_rx *oam_channel =
                                   (bcmbal_packet_ieee_oam_channel_rx *)obj;
 
-      balIndCfg.baloamresp->key->has_reserved = BAL_GRPC_PRES; 
-      balIndCfg.baloamresp->key->reserved = oam_channel->key.reserved; 
+      balIndCfg.baloamresp->key->has_reserved = BAL_GRPC_PRES;
+      balIndCfg.baloamresp->key->reserved = oam_channel->key.reserved;
 
       BalDest PktSndDest;
       memset(&PktSndDest, 0, sizeof(BalDest));
@@ -1769,7 +1828,7 @@
       balIndCfg.baloamresp->key->packet_send_dest = &PktSndDest;
 
       balIndCfg.baloamresp->key->packet_send_dest->has_type = BAL_GRPC_PRES;
-      balIndCfg.baloamresp->key->packet_send_dest->type = 
+      balIndCfg.baloamresp->key->packet_send_dest->type =
                                           oam_channel->key.packet_send_dest.type;
       switch( oam_channel->key.packet_send_dest.type)
       {
@@ -1780,15 +1839,17 @@
             memset(&balOam, 0, sizeof(BalIeeeOamChannel));
             bal_ieee_oam_channel__init(&balOam);
             balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel = &balOam;
-            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->has_intf_id = 
+            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->has_intf_id =
                                                                             BAL_GRPC_PRES;
-            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->intf_id = 
+            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->intf_id =
                                  oam_channel->key.packet_send_dest.u.ieee_oam_channel.intf_id;
-            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->has_mac_address = BAL_GRPC_PRES; 
-            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->mac_address.len = 
+            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->has_mac_address = BAL_GRPC_PRES;
+            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->mac_address.len =
                (BCMOS_ETH_ALEN)*sizeof(oam_channel->key.packet_send_dest.u.ieee_oam_channel.mac_address.u8);
-            memcpy(balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->mac_address.data, 
-                   oam_channel->key.packet_send_dest.u.ieee_oam_channel.mac_address.u8, 
+            balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->mac_address.data =
+             (uint8_t *)malloc((balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->mac_address.len)*sizeof(uint8_t));
+            memcpy(balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->mac_address.data,
+                   oam_channel->key.packet_send_dest.u.ieee_oam_channel.mac_address.u8,
                    balIndCfg.baloamresp->key->packet_send_dest->ieee_oam_channel->mac_address.len);
 
          }
@@ -1803,9 +1864,10 @@
       BalPacketIeeeOamChannelRxData oamData;
       memset(&oamData, 0, sizeof(BalPacketIeeeOamChannelRxData));
       bal_packet_ieee_oam_channel_rx_data__init(&oamData);
-      balIndCfg.baloamresp->data = &oamData; 
+      balIndCfg.baloamresp->data = &oamData;
 
       balIndCfg.baloamresp->data->pkt.len =  oam_channel->data.pkt.len;
+      balIndCfg.baloamresp->data->pkt.data = (uint8_t *)malloc((balIndCfg.baloamresp->data->pkt.len)*sizeof(uint8_t));
       memcpy(balIndCfg.baloamresp->data->pkt.data, oam_channel->data.pkt.val,
              balIndCfg.baloamresp->data->pkt.len);
 
diff --git a/src/bal_packet_hdlr.c b/src/bal_packet_hdlr.c
index ec2129c..5f01c1d 100755
--- a/src/bal_packet_hdlr.c
+++ b/src/bal_packet_hdlr.c
@@ -30,6 +30,8 @@
 
 #include "asfvolt16_driver.h"
 #include "bal_packet_hdlr.h"
+static bcmos_mutex bal_ind_lock;
+
 
 /********************************************************************\
  * Function    : bal_access_terminal_cfg_req                        *
@@ -38,28 +40,61 @@
  ********************************************************************/
 uint32_t bal_packet_cfg_req(BalPacketCfg *packet)
 {
+   bcmos_mutex_lock(&bal_ind_lock);
    bcmos_errno err = BCM_ERR_OK;
+   bcmbal_access_term_id aterm_id = 0; /* Assume a single access_terminal instance */
+   bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
    switch(packet->key->packet_send_dest->type)
    {
       case BAL_DEST_TYPE__BAL_DEST_TYPE_NNI:
          {
-            ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Send packet msg to NNI not yet implemented\n");
+            bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_NNI,
+               .u.nni.intf_id = packet->key->packet_send_dest->nni->intf_id };
+            buf.len = packet->data->pkt.len;
+            buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
+            memcpy(buf.val,(uint8_t *)packet->data->pkt.data,buf.len);
+	    ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Packet of length %d bytes with dest type as %d\n",buf.len,packet->key->packet_send_dest->type);
+            err = bcmbal_pkt_send(aterm_id,
+                  proxy_pkt_dest,
+                  (const char *)(buf.val),
+                  buf.len);
+            free(buf.val);
          }
          break;
       case BAL_DEST_TYPE__BAL_DEST_TYPE_SUB_TERM:
          {
-            ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Send packet msg to ONU not yet implemented\n");
+            bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_SUB_TERM,
+               .u.sub_term.sub_term_id = packet->key->packet_send_dest->sub_term->sub_term_id,
+               .u.sub_term.intf_id = packet->key->packet_send_dest->sub_term->intf_id };
+            buf.len = packet->data->pkt.len;
+            buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
+            memcpy(buf.val,(uint8_t *)packet->data->pkt.data,buf.len);
+	    ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Packet of length %d bytes with dest type as %d\n",buf.len,packet->key->packet_send_dest->type);
+            err = bcmbal_pkt_send(aterm_id,
+                  proxy_pkt_dest,
+                  (const char *)(buf.val),
+                  buf.len);
+            free(buf.val);
          }
          break;
       case BAL_DEST_TYPE__BAL_DEST_TYPE_SVC_PORT:
          {
-            ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Send packet msg to PON not yet implemented\n");
+            bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_SVC_PORT,
+               .u.svc_port.svc_port_id = packet->key->packet_send_dest->svc_port->svc_port_id,
+               .u.svc_port.intf_id = packet->key->packet_send_dest->svc_port->intf_id };
+            buf.len = packet->data->pkt.len;
+            buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
+	    ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Packet of length %d bytes with dest type as %d\n",buf.len,packet->key->packet_send_dest->type);
+            memcpy(buf.val,(uint8_t *)packet->data->pkt.data,buf.len);
+            err = bcmbal_pkt_send(aterm_id,
+                  proxy_pkt_dest,
+                  (const char *)(buf.val),
+                  buf.len);
+            free(buf.val);
          }
          break;
       case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL:
          {
-            bcmbal_access_term_id aterm_id = 0; /* Assume a single access_terminal instance */
-            bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
             /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
             bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL,
                .u.itu_omci_channel.sub_term_id = packet->key->packet_send_dest->itu_omci_channel->sub_term_id,
@@ -82,7 +117,7 @@
             }
             buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
             memcpy(buf.val,(uint8_t *)arraySend,buf.len);
-            ASFVOLT_LOG(ASFVOLT_DEBUG,"\nAfter converting it into hex\n");
+            ASFVOLT_LOG(ASFVOLT_DEBUG,"\nAfter converting it into hex ");
             for(idx2=0; idx2<buf.len; idx2++)
             {
                printf("%02x", buf.val[idx2]);
@@ -96,7 +131,7 @@
                   buf.len,
                   packet->key->packet_send_dest->itu_omci_channel->sub_term_id,
                   packet->key->packet_send_dest->itu_omci_channel->intf_id);
-            bcmos_free(buf.val); 
+            free(buf.val);
          }
          break;
       case BAL_DEST_TYPE__BAL_DEST_TYPE_IEEE_OAM_CHANNEL:
@@ -114,5 +149,6 @@
    {
       /* recover from any error encountered while sending */
    }
+   bcmos_mutex_unlock(&bal_ind_lock);
    return err;
 }
diff --git a/src/bal_stats_hdlr.c b/src/bal_stats_hdlr.c
index b1c49d2..0c0de39 100755
--- a/src/bal_stats_hdlr.c
+++ b/src/bal_stats_hdlr.c
@@ -16,6 +16,8 @@
 
 #include "bal_stats_hdlr.h"
 
+#define BAL_STAT_PRES   1
+
 /********************************************************************\
  * Function : asfvolt16_bal_stats_get                               *
  * Description : Function to get stats based on                     *
@@ -24,67 +26,67 @@
  ********************************************************************/
 uint32_t asfvolt16_bal_stats_get(BalIntfType intf_type, uint32_t intf_id, BalInterfaceStatData *statData)
 {
-	bcmbal_interface_stat interface_stats;
+   bcmbal_interface_stat interface_stats;
 
-	bcmos_errno err = BCM_ERR_OK;
+   bcmos_errno err = BCM_ERR_OK;
 
-	if(intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_NNI || intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_PON||
-		intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_EPON_1G_PATH ||
-		intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_EPON_10G_PATH)
-	{
-		err = BCM_ERR_PARM;
-	}
+   ASFVOLT_LOG(ASFVOLT_DEBUG, "Get Stats from OLT intf_type %d\n",intf_type);
 
-	if(err == BCM_ERR_OK)
-	{
-		bcmbal_interface_key key = { .intf_id = intf_id,
-								.intf_type = intf_type };
+   if(intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_NNI && intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_PON &&
+	intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_EPON_1G_PATH &&
+	intf_type!=BAL_INTF_TYPE__BAL_INTF_TYPE_EPON_10G_PATH)
+   {
+      return BCM_ERR_PARM;
+   }
 
-		/* Prepare to retrieve stat on NNI interface 0 */
-		BCMBAL_STAT_INIT(&interface_stats, interface, key);
+   bcmbal_interface_key key = { .intf_id = intf_id, .intf_type = intf_type };
 
-		/* Retrieve the Upstream packet and byte counts */
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_bytes);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_ucast_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_mcast_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_bcast_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_error_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_unknown_protos);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, tx_bytes);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, tx_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, tx_ucast_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, tx_mcast_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, tx_bcast_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, tx_error_packets);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, rx_crc_errors);
-		BCMBAL_STAT_PROP_GET(&interface_stats, interface, bip_errors);
-   
-		/* Read the NNI stats.
-			* NOTE: When a CLEAR is specified during a NNI stats GET operation,
-			* all of the NNI stats are cleared, even the ones that are not retrieved.
-			*/
-		err = bcmbal_stat_get(DEFAULT_ATERM_ID, &interface_stats.hdr, BCMOS_TRUE);
+   /* Prepare to retrieve stat on NNI interface 0 */
+   BCMBAL_STAT_INIT(&interface_stats, interface, key);
 
-		if(err == BCM_ERR_OK)
-		{
-			statData->rx_bytes = interface_stats.data.rx_bytes;
-        	statData->rx_packets = interface_stats.data.rx_packets;
-        	statData->rx_ucast_packets = interface_stats.data.rx_ucast_packets;        
-        	statData->rx_mcast_packets = interface_stats.data.rx_mcast_packets;
-        	statData->rx_bcast_packets = interface_stats.data.rx_bcast_packets;
-        	statData->rx_error_packets = interface_stats.data.rx_error_packets;
-        	statData->rx_unknown_protos = interface_stats.data.rx_unknown_protos;
-        	statData->tx_bytes = interface_stats.data.tx_bytes;
-        	statData->tx_packets = interface_stats.data.tx_packets;
-        	statData->tx_ucast_packets = interface_stats.data.tx_ucast_packets;
-        	statData->tx_mcast_packets = interface_stats.data.tx_mcast_packets;
-        	statData->tx_bcast_packets = interface_stats.data.tx_bcast_packets;
-        	statData->tx_error_packets = interface_stats.data.tx_error_packets;
-        	statData->rx_crc_errors = interface_stats.data.rx_crc_errors;
-        	statData->bip_errors = interface_stats.data.bip_errors;
-		}
-	}
+   /* Retrieve the Upstream packet and byte counts */
+   BCMBAL_STAT_PROP_GET(&interface_stats, interface, all_properties);
+   ASFVOLT_LOG(ASFVOLT_DEBUG, "Retrieve the Upstream packet and byte count success\n");
 
-	return err;
+   /* Read the NNI stats.
+    * NOTE: When a CLEAR is specified during a NNI stats GET operation,
+    * all of the NNI stats are cleared, even the ones that are not retrieved.
+    */
+   err = bcmbal_stat_get(DEFAULT_ATERM_ID, &interface_stats.hdr, BCMOS_TRUE);
+
+   if(err == BCM_ERR_OK)
+   {
+      statData->has_rx_bytes = BAL_STAT_PRES;
+      statData->rx_bytes = interface_stats.data.rx_bytes;
+      statData->has_rx_packets = BAL_STAT_PRES;
+      statData->rx_packets = interface_stats.data.rx_packets;
+      statData->has_rx_ucast_packets = BAL_STAT_PRES;
+      statData->rx_ucast_packets = interface_stats.data.rx_ucast_packets;
+      statData->has_rx_mcast_packets = BAL_STAT_PRES;
+      statData->rx_mcast_packets = interface_stats.data.rx_mcast_packets;
+      statData->has_rx_bcast_packets = BAL_STAT_PRES;
+      statData->rx_bcast_packets = interface_stats.data.rx_bcast_packets;
+      statData->has_rx_error_packets = BAL_STAT_PRES;
+      statData->rx_error_packets = interface_stats.data.rx_error_packets;
+      statData->has_rx_unknown_protos = BAL_STAT_PRES;
+      statData->rx_unknown_protos = interface_stats.data.rx_unknown_protos;
+      statData->has_tx_bytes = BAL_STAT_PRES;
+      statData->tx_bytes = interface_stats.data.tx_bytes;
+      statData->has_tx_packets = BAL_STAT_PRES;
+      statData->tx_packets = interface_stats.data.tx_packets;
+      statData->has_tx_ucast_packets = BAL_STAT_PRES;
+      statData->tx_ucast_packets = interface_stats.data.tx_ucast_packets;
+      statData->has_tx_mcast_packets = BAL_STAT_PRES;
+      statData->tx_mcast_packets = interface_stats.data.tx_mcast_packets;
+      statData->has_tx_bcast_packets = BAL_STAT_PRES;
+      statData->tx_bcast_packets = interface_stats.data.tx_bcast_packets;
+      statData->has_tx_error_packets = BAL_STAT_PRES;
+      statData->tx_error_packets = interface_stats.data.tx_error_packets;
+      statData->has_rx_crc_errors = BAL_STAT_PRES;
+      statData->rx_crc_errors = interface_stats.data.rx_crc_errors;
+      statData->has_bip_errors = BAL_STAT_PRES;
+      statData->bip_errors = interface_stats.data.bip_errors;
+   }
+
+   return err;
 }