Initial commit.

Change-Id: I53f8c2f96fe4ce2f7855e950a38e812286c6c9de
diff --git a/src/Queue.h b/src/Queue.h
new file mode 100644
index 0000000..854851e
--- /dev/null
+++ b/src/Queue.h
@@ -0,0 +1,60 @@
+//
+// Copyright (c) 2013 Juan Palacios juan.palacios.puyana@gmail.com
+// Subject to the BSD 2-Clause License
+// - see < http://opensource.org/licenses/BSD-2-Clause>
+//
+
+#ifndef CONCURRENT_QUEUE_
+#define CONCURRENT_QUEUE_
+
+#include <queue>
+#include <thread>
+#include <mutex>
+#include <condition_variable>
+
+template <typename T>
+class Queue
+{
+ public:
+
+  T pop() 
+  {
+    std::unique_lock<std::mutex> mlock(mutex_);
+    while (queue_.empty())
+    {
+      cond_.wait(mlock);
+    }
+    auto val = queue_.front();
+    queue_.pop();
+    return val;
+  }
+
+  void pop(T& item)
+  {
+    std::unique_lock<std::mutex> mlock(mutex_);
+    while (queue_.empty())
+    {
+      cond_.wait(mlock);
+    }
+    item = queue_.front();
+    queue_.pop();
+  }
+
+  void push(const T& item)
+  {
+    std::unique_lock<std::mutex> mlock(mutex_);
+    queue_.push(item);
+    mlock.unlock();
+    cond_.notify_one();
+  }
+  Queue()=default;
+  Queue(const Queue&) = delete;            // disable copying
+  Queue& operator=(const Queue&) = delete; // disable assignment
+  
+ private:
+  std::queue<T> queue_;
+  std::mutex mutex_;
+  std::condition_variable cond_;
+};
+
+#endif
diff --git a/src/indications.cc b/src/indications.cc
new file mode 100644
index 0000000..78eb3b2
--- /dev/null
+++ b/src/indications.cc
@@ -0,0 +1,413 @@
+/*
+    Copyright (C) 2018 Open Networking Foundation
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "indications.h"
+#include "server.h"
+#include "utils.h"
+extern "C"
+{
+#include <bcmos_system.h>
+#include <bal_api.h>
+#include <bal_api_end.h>
+}
+
+using grpc::Status;
+
+Queue<openolt::Indication> oltIndQ;
+//Queue<openolt::Indication*> oltIndQ;
+
+bool subscribed = false;
+
+bcmos_errno OmciIndication(bcmbal_obj *obj);
+
+bcmos_errno OltIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    openolt::OltIndication* olt_ind = new openolt::OltIndication;
+    Status status;
+
+    bcmbal_access_terminal_ind *acc_term_ind = (bcmbal_access_terminal_ind *)obj;
+    if (acc_term_ind->data.oper_status == BCMBAL_STATUS_UP) {
+        olt_ind->set_oper_state("up");
+    } else {
+        olt_ind->set_oper_state("down");
+    }
+    ind.set_allocated_olt_ind(olt_ind);
+    std::cout << "olt indication, oper_state:" << ind.olt_ind().oper_state() << std::endl;
+    oltIndQ.push(ind);
+
+    // Enable all PON interfaces.
+    for (int i = 0; i < MAX_SUPPORTED_INTF; i++) {
+        status = EnablePonIf_(i);
+        if (!status.ok()) {
+            // FIXME - raise alarm to report error in enabling PON
+        }
+    }
+
+    /* register for omci indication */
+    {
+        bcmbal_cb_cfg cb_cfg = {};
+        uint16_t ind_subgroup;
+
+        cb_cfg.module = BCMOS_MODULE_ID_NONE;
+        cb_cfg.obj_type = BCMBAL_OBJ_ID_PACKET;
+        ind_subgroup = BCMBAL_IND_SUBGROUP(packet, itu_omci_channel_rx);
+        cb_cfg.p_object_key_info = NULL;
+        cb_cfg.p_subgroup = &ind_subgroup;
+        cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OmciIndication;
+        bcmbal_subscribe_ind(0, &cb_cfg);
+    }
+
+    return BCM_ERR_OK;
+}
+
+bcmos_errno LosIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "LOS indication " << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno IfIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    openolt::IntfIndication* intf_ind = new openolt::IntfIndication;
+
+    std::cout << "intf indication, intf_id:"
+              << ((bcmbal_interface_ind *)obj)->key.intf_id << std::endl;
+
+    intf_ind->set_intf_id(((bcmbal_interface_ind *)obj)->key.intf_id);
+    if (((bcmbal_interface_ind *)obj)->data.oper_status == BCMBAL_STATUS_UP) {
+        intf_ind->set_oper_state("up");
+    } else {
+        intf_ind->set_oper_state("down");
+    }
+    ind.set_allocated_intf_ind(intf_ind);
+
+    oltIndQ.push(ind);
+
+    return BCM_ERR_OK;
+}
+
+bcmos_errno IfOperIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    openolt::IntfOperIndication* intf_oper_ind = new openolt::IntfOperIndication;
+    std::cout << "intf oper state indication, intf_id:"
+              << ((bcmbal_interface_ind *)obj)->key.intf_id
+              << " type:" << ((bcmbal_interface_oper_status_change *)obj)->key.intf_type
+              << " oper_state:" << ((bcmbal_interface_oper_status_change *)obj)->data.new_oper_status
+              << " admin_state:" << ((bcmbal_interface_oper_status_change *)obj)->data.admin_state
+              << std::endl;
+
+    intf_oper_ind->set_intf_id(((bcmbal_interface_oper_status_change *)obj)->key.intf_id);
+
+    if (((bcmbal_interface_oper_status_change *)obj)->key.intf_type == BCMBAL_INTF_TYPE_NNI) {
+        intf_oper_ind->set_type("nni");
+    } else if (((bcmbal_interface_oper_status_change *)obj)->key.intf_type == BCMBAL_INTF_TYPE_PON) {
+        intf_oper_ind->set_type("pon");
+    } else {
+        intf_oper_ind->set_type("unknown");
+    }
+
+    if (((bcmbal_interface_oper_status_change *)obj)->data.new_oper_status == BCMBAL_STATUS_UP) {
+        intf_oper_ind->set_oper_state("up");
+    } else {
+        intf_oper_ind->set_oper_state("down");
+    }
+
+    ind.set_allocated_intf_oper_ind(intf_oper_ind);
+
+    oltIndQ.push(ind);
+    return BCM_ERR_OK;
+}
+
+bcmos_errno OnuAlarmIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "onu alarm indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno OnuDyingGaspIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "onu dying-gasp indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno OnuDiscoveryIndication(bcmbal_cfg *obj) {
+    openolt::Indication ind;
+    openolt::OnuDiscIndication* onu_disc_ind = new openolt::OnuDiscIndication;
+    openolt::SerialNumber* serial_number = new openolt::SerialNumber;
+
+    bcmbal_subscriber_terminal_key *key =
+        &(((bcmbal_subscriber_terminal_sub_term_disc*)obj)->key);
+
+    bcmbal_subscriber_terminal_sub_term_disc_data *data =
+        &(((bcmbal_subscriber_terminal_sub_term_disc*)obj)->data);
+
+    bcmbal_serial_number *in_serial_number = &(data->serial_number);
+
+    std::cout << "onu discover indication, intf_id:"
+         << key->intf_id
+         << " serial_number:"
+         << serial_number_to_str(in_serial_number) << std::endl;
+
+    onu_disc_ind->set_intf_id(key->intf_id);
+    serial_number->set_vendor_id(reinterpret_cast<const char *>(in_serial_number->vendor_id), 4);
+    serial_number->set_vendor_specific(reinterpret_cast<const char *>(in_serial_number->vendor_specific), 8);
+    onu_disc_ind->set_allocated_serial_number(serial_number);
+    ind.set_allocated_onu_disc_ind(onu_disc_ind);
+
+    oltIndQ.push(ind);
+
+    return BCM_ERR_OK;
+}
+
+bcmos_errno OnuIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    openolt::OnuIndication* onu_ind = new openolt::OnuIndication;
+    openolt::SerialNumber* serial_number = new openolt::SerialNumber;
+
+    bcmbal_subscriber_terminal_key *key =
+        &(((bcmbal_subscriber_terminal_ind*)obj)->key);
+
+    bcmbal_subscriber_terminal_ind_data *data =
+        &(((bcmbal_subscriber_terminal_ind*)obj)->data);
+
+    bcmbal_serial_number *in_serial_number = &(data->serial_number);
+
+    std::cout << "onu indication, intf_id:"
+         << key->intf_id
+         << " serial_number:"
+         << serial_number_to_str(in_serial_number) << std::endl;
+
+    onu_ind->set_intf_id(key->intf_id);
+    onu_ind->set_onu_id(key->sub_term_id);
+    serial_number->set_vendor_id(reinterpret_cast<const char *>(in_serial_number->vendor_id), 4);
+    serial_number->set_vendor_specific(reinterpret_cast<const char *>(in_serial_number->vendor_specific), 8);
+    onu_ind->set_allocated_serial_number(serial_number);
+    ind.set_allocated_onu_ind(onu_ind);
+
+    oltIndQ.push(ind);
+    return BCM_ERR_OK;
+}
+
+bcmos_errno OnuOperIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "onu oper state indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno OmciIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    openolt::OmciIndication* omci_ind = new openolt::OmciIndication;
+    bcmbal_packet_itu_omci_channel_rx *omci_channel =
+        (bcmbal_packet_itu_omci_channel_rx *)obj;
+
+    std::cout << "omci indication" << std::endl;
+
+    omci_ind->set_intf_id(
+        omci_channel->key.packet_send_dest.u.itu_omci_channel.intf_id);
+    omci_ind->set_onu_id(
+        omci_channel->key.packet_send_dest.u.itu_omci_channel.sub_term_id);
+    omci_ind->set_pkt(omci_channel->data.pkt.val, omci_channel->data.pkt.len);
+
+    ind.set_allocated_omci_ind(omci_ind);
+    oltIndQ.push(ind);
+
+    return BCM_ERR_OK;
+}
+
+bcmos_errno PacketInIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "packet-in indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno FlowOperIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "flow oper state indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno FlowIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "flow indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno TmQIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "traffic mgmt queue indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno TmSchedIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "traffic mgmt sheduler indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+bcmos_errno McastGroupIndication(bcmbal_obj *obj) {
+    openolt::Indication ind;
+    std::cout << "mcast group indication" << std::endl;
+    return BCM_ERR_OK;
+}
+
+Status SubscribeIndication() {
+    bcmbal_cb_cfg cb_cfg = {};
+    uint16_t ind_subgroup;
+
+    if (subscribed) {
+        return Status::OK;
+    }
+
+    cb_cfg.module = BCMOS_MODULE_ID_NONE;
+
+
+    /* OLT device indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_ACCESS_TERMINAL;
+    ind_subgroup = bcmbal_access_terminal_auto_id_ind;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OltIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Olt indication subscribe failed");
+    }
+
+    /* Interface LOS indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
+    ind_subgroup = bcmbal_interface_auto_id_los;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)LosIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "LOS indication subscribe failed");
+    }
+
+    /* Interface indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
+    ind_subgroup = bcmbal_interface_auto_id_ind;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)IfIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Interface indication subscribe failed");
+    }
+
+    /* Interface operational state change indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_INTERFACE;
+    ind_subgroup = bcmbal_interface_auto_id_oper_status_change;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)IfOperIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Interface operations state change indication subscribe failed");
+    }
+
+    /* onu alarm indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
+    ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_alarm;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuAlarmIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "onu alarm indication subscribe failed");
+    }
+
+    /* onu dying-gasp indication  */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
+    ind_subgroup = bcmbal_subscriber_terminal_auto_id_dgi;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuDyingGaspIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "onu dying-gasp indication subscribe failed");
+    }
+
+    /* onu discovery indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
+    ind_subgroup = bcmbal_subscriber_terminal_auto_id_sub_term_disc;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuDiscoveryIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "onu discovery indication subscribe failed");
+    }
+
+    /* onu indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
+    ind_subgroup = bcmbal_subscriber_terminal_auto_id_ind;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "onu indication subscribe failed");
+    }
+    /* onu operational state change indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL;
+    ind_subgroup = bcmbal_subscriber_terminal_auto_id_oper_status_change;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)OnuOperIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "onu operational state change indication subscribe failed");
+    }
+
+    /* Packet-in indications */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_PACKET;
+    ind_subgroup = bcmbal_packet_auto_id_bearer_channel_rx;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)PacketInIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Packet-in indication subscribe failed");
+    }
+
+    /* Flow Operational State Change */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
+    ind_subgroup = bcmbal_flow_auto_id_oper_status_change;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)FlowOperIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Flow operational state change indication subscribe failed");
+    }
+    /* Flow Indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_FLOW;
+    ind_subgroup = bcmbal_flow_auto_id_ind;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)FlowIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Flow indication subscribe failed");
+    }
+
+    /* TM queue indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_QUEUE;
+    ind_subgroup = bcmbal_tm_queue_auto_id_ind;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)TmQIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Traffic mgmt queue indication subscribe failed");
+    }
+
+    /* TM sched indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_TM_SCHED;
+    ind_subgroup = bcmbal_tm_sched_auto_id_ind;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)TmSchedIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Traffic mgmt queue indication subscribe failed");
+    }
+
+    /* Multicast group indication */
+    cb_cfg.obj_type = BCMBAL_OBJ_ID_GROUP;
+    ind_subgroup = bcmbal_group_auto_id_ind;
+    cb_cfg.p_subgroup = &ind_subgroup;
+    cb_cfg.ind_cb_hdlr = (f_bcmbal_ind_handler)McastGroupIndication;
+    if (BCM_ERR_OK != bcmbal_subscribe_ind(DEFAULT_ATERM_ID, &cb_cfg)) {
+        return Status(grpc::StatusCode::INTERNAL, "Multicast group indication subscribe failed");
+    }
+
+    subscribed = true;
+
+    return Status::OK;
+}
diff --git a/src/indications.h b/src/indications.h
new file mode 100644
index 0000000..2160aa6
--- /dev/null
+++ b/src/indications.h
@@ -0,0 +1,27 @@
+/*
+    Copyright (C) 2018 Open Networking Foundation 
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef OPENASF_INDICATIONS_H_
+#define OPENASF_INDICATIONS_H_
+#include <grpc++/grpc++.h>
+#include <openolt.grpc.pb.h>
+#include "Queue.h"
+
+extern Queue<openolt::Indication> oltIndQ;
+extern grpc::Status SubscribeIndication();
+
+#endif
diff --git a/src/indications.o b/src/indications.o
new file mode 100644
index 0000000..afb1925
--- /dev/null
+++ b/src/indications.o
Binary files differ
diff --git a/src/main.cc b/src/main.cc
new file mode 100644
index 0000000..3f8fba4
--- /dev/null
+++ b/src/main.cc
@@ -0,0 +1,56 @@
+/*
+    Copyright (C) 2018 Open Networking Foundation 
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <iostream>
+
+#include "indications.h"
+#include "server.h"
+
+extern "C"
+{
+#include <bal_api.h>
+#include <bal_api_end.h>
+}
+
+int main(int argc, char** argv) {
+
+    if (argc < 5) {
+        std::cout << "Missing arguments" << std::endl;
+        exit(1);
+    }
+
+    bcmbal_init(argc, argv, NULL);
+
+    Status status = SubscribeIndication();
+    if (!status.ok()) {
+        std::cout << "ERROR: SubscribeIndication failed - "
+                  << status.error_code() << ": " << status.error_message()
+                  << std::endl;
+        return 1;
+    }
+
+    status = Enable_();
+    if (!status.ok()) {
+        std::cout << "ERROR: Enable_ failed - "
+                  << status.error_code() << ": " << status.error_message()
+                  << std::endl;
+        return 1;
+    }
+
+    RunServer();
+
+  return 0;
+}
diff --git a/src/main.o b/src/main.o
new file mode 100644
index 0000000..1098108
--- /dev/null
+++ b/src/main.o
Binary files differ
diff --git a/src/server.cc b/src/server.cc
new file mode 100644
index 0000000..25594d4
--- /dev/null
+++ b/src/server.cc
@@ -0,0 +1,478 @@
+/*
+    Copyright (C) 2018 Open Networking Foundation 
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <iostream>
+#include <memory>
+#include <string>
+
+#include "Queue.h"
+#include <iostream>
+#include <sstream>
+
+#include "server.h"
+#include "indications.h"
+
+extern "C"
+{
+#include <bcmos_system.h>
+#include <bal_api.h>
+#include <bal_api_end.h>
+}
+#include <openolt.grpc.pb.h>
+
+using grpc::Server;
+using grpc::ServerBuilder;
+using grpc::ServerContext;
+using grpc::ServerWriter;
+
+const char *serverPort = "0.0.0.0:9191";
+
+class OpenoltService final : public openolt::Openolt::Service {
+
+    Status ActivateOnu(
+            ServerContext* context,
+            const openolt::Onu* request,
+            openolt::Empty* response) override {
+        return ActivateOnu_(
+            request->intf_id(),
+            request->onu_id(),
+            ((request->serial_number()).vendor_id()).c_str(),
+            ((request->serial_number()).vendor_specific()).c_str());
+    }
+
+    Status OmciMsgOut(
+            ServerContext* context,
+            const openolt::OmciMsg* request,
+            openolt::Empty* response) override {
+        return OmciMsgOut_(
+            request->intf_id(),
+            request->onu_id(),
+            request->pkt());
+    }
+
+    Status FlowAdd(
+            ServerContext* context,
+            const openolt::Flow* request,
+            openolt::Empty* response) override {
+        return FlowAdd_(
+            request->onu_id(),
+            request->flow_id(),
+            request->flow_type(),
+            request->access_intf_id(),
+            request->network_intf_id(),
+            request->gemport_id(),
+            request->classifier(),
+            request->action());
+    }
+
+    Status EnableIndication(
+            ServerContext* context,
+            const ::openolt::Empty* request,
+            ServerWriter<openolt::Indication>* writer) override {
+        while (1) {
+            auto oltInd = oltIndQ.pop();
+            writer->Write(oltInd);
+            //oltInd.release_olt_ind()
+        }
+        return Status::OK;
+    }
+};
+
+void RunServer() {
+  OpenoltService service;
+  std::string server_address(serverPort);
+  ServerBuilder builder;
+
+  builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
+  builder.RegisterService(&service);
+
+  std::unique_ptr<Server> server(builder.BuildAndStart());
+
+  std::cout << "Server listening on " << server_address << std::endl;
+
+  server->Wait();
+}
+
+Status Enable_() {
+    static bool enabled = false;
+    bcmbal_access_terminal_cfg acc_term_obj;
+    bcmbal_access_terminal_key key = { };
+
+    if (!enabled) {
+        std::cout << "Enable OLT" << std::endl;
+        key.access_term_id = DEFAULT_ATERM_ID;
+        BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key);
+        BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP);
+        if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr))) {
+            std::cout << "ERROR: Failed to enable OLT" << std::endl;
+            return Status(grpc::StatusCode::INTERNAL, "Failed to enable OLT");
+        }
+        enabled = true;
+    }
+    return Status::OK;
+}
+
+Status EnablePonIf_(uint32_t intf_id) {
+    bcmbal_interface_cfg interface_obj;
+    bcmbal_interface_key interface_key;
+    
+    interface_key.intf_id = intf_id;
+    interface_key.intf_type = BCMBAL_INTF_TYPE_PON;
+
+    BCMBAL_CFG_INIT(&interface_obj, interface, interface_key);
+    BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP);
+
+    if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr))) {
+        std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl;
+        return Status(grpc::StatusCode::INTERNAL, "Failed to enable PON interface");
+    }
+
+    return Status::OK;
+}
+
+Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
+    const char *vendor_id, const char *vendor_specific) {
+
+    bcmbal_subscriber_terminal_cfg sub_term_obj = {};
+    bcmbal_subscriber_terminal_key subs_terminal_key;
+    bcmbal_serial_number serial_num = {};
+    bcmbal_registration_id registration_id = {};
+
+    std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl;
+    std::cout << "Vendor Id " << vendor_id
+              << "Vendor Specific Id " << vendor_specific
+              << std::endl;
+
+    subs_terminal_key.sub_term_id = onu_id;
+    subs_terminal_key.intf_id = intf_id;
+    BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
+
+    memcpy(serial_num.vendor_id, vendor_id, 4);
+    memcpy(serial_num.vendor_specific, vendor_specific, 4);
+    BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num);
+
+    // FIXME - Use a default (all zeros) registration id.
+    memset(registration_id.arr, 0, sizeof(registration_id.arr));
+    BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id);
+
+    BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP);
+
+    if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) {
+        std::cout << "ERROR: Failed to enable ONU: " << std::endl;
+        return Status(grpc::StatusCode::INTERNAL, "Failed to enable ONU");
+    }
+
+    return SchedAdd_(intf_id, onu_id, mk_agg_port_id(onu_id));
+
+    //return Status::OK;
+}
+
+#define MAX_CHAR_LENGTH  20
+#define MAX_OMCI_MSG_LENGTH 44
+Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) {
+    bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
+    bcmos_errno err = BCM_ERR_OK;
+
+    /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
+    bcmbal_dest proxy_pkt_dest;
+
+    proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL;
+    proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id;
+    proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id;
+
+    // ???
+    if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) {
+        buf.len = MAX_OMCI_MSG_LENGTH;
+    } else {
+        buf.len = pkt.size()/2;
+    }
+
+    /* Send the OMCI packet using the BAL remote proxy API */
+    uint16_t idx1 = 0;
+    uint16_t idx2 = 0;
+    uint8_t arraySend[buf.len];
+    char str1[MAX_CHAR_LENGTH];
+    char str2[MAX_CHAR_LENGTH];
+    memset(&arraySend, 0, buf.len);
+
+    std::cout << "Sending omci msg to ONU of length is "
+         << buf.len
+         << std::endl;
+
+    for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) {
+       sprintf(str1,"%c", pkt[idx1]);
+       sprintf(str2,"%c", pkt[++idx1]);
+       strcat(str1,str2);
+       arraySend[idx2] = strtol(str1, NULL, 16);
+    }
+
+    buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
+    memcpy(buf.val,(uint8_t *)arraySend,buf.len);
+
+    std::cout << "After converting bytes to hex "
+              << buf.val << buf.len << std::endl;
+
+    err = bcmbal_pkt_send(0, proxy_pkt_dest,
+                         (const char *)(buf.val), buf.len);
+
+    std::cout << "OMCI request msg of length " << buf.len
+              << " sent to ONU" << onu_id
+              << " through PON " << intf_id << std::endl;
+
+    free(buf.val);
+
+    return Status::OK;
+}
+
+Status FlowAdd_(uint32_t onu_id,
+                uint32_t flow_id, const std::string flow_type,
+                uint32_t access_intf_id, uint32_t network_intf_id,
+                uint32_t gemport_id,
+                const ::openolt::Classifier& classifier,
+                const ::openolt::Action& action) {
+    bcmos_errno err;
+    bcmbal_flow_cfg cfg;
+    bcmbal_flow_key key = { };
+
+    std::cout << "flow add -"
+              << " intf_id:" << access_intf_id
+              << " onu_id:" << onu_id
+              << " flow_id:" << flow_id
+              << " flow_type:" << flow_type
+              << " gemport_id:" << gemport_id
+              << " network_intf_id:" << network_intf_id
+              << std::endl;
+
+    key.flow_id = flow_id;
+    if (flow_type.compare("upstream") == 0 ) {
+        key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM;
+    } else if (flow_type.compare("downstream") == 0) {
+        key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM;
+    } else {
+        std::cout << "Invalid flow type " << flow_type << std::endl;
+        return Status::CANCELLED;
+    }
+
+    BCMBAL_CFG_INIT(&cfg, flow, key);
+
+    BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP);
+    BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id);
+    BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id);
+    BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id);
+    BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id);
+
+    {
+        bcmbal_classifier val = { };
+
+        if (classifier.o_tpid()) {
+            val.o_tpid = classifier.o_tpid();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID;
+        }
+
+        if (classifier.o_vid()) {
+            val.o_vid = classifier.o_vid();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID;
+        }
+
+        if (classifier.i_tpid()) {
+            val.i_tpid = classifier.i_tpid();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID;
+        }
+
+        if (classifier.i_vid()) {
+            val.i_vid = classifier.i_vid();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID;
+        }
+
+        if (classifier.o_pbits()) {
+            val.o_pbits = classifier.o_pbits();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS;
+        }
+
+        if (classifier.i_pbits()) {
+            val.i_pbits = classifier.i_pbits();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS;
+        }
+
+        if (classifier.eth_type()) {
+            val.ether_type = classifier.eth_type();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE;
+        }
+
+        /*
+        if (classifier.dst_mac()) {
+            val.dst_mac = classifier.dst_mac();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC;
+        }
+
+        if (classifier.src_mac()) {
+            val.src_mac = classifier.src_mac();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC;
+        }
+        */
+
+        if (classifier.ip_proto()) {
+            val.ip_proto = classifier.ip_proto();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO;
+        }
+
+        /*
+        if (classifier.dst_ip()) {
+            val.dst_ip = classifier.dst_ip();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP;
+        }
+
+        if (classifier.src_ip()) {
+            val.src_ip = classifier.src_ip();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP;
+        }
+        */
+
+        if (classifier.src_port()) {
+            val.src_port = classifier.src_port();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT;
+        }
+
+        if (classifier.dst_port()) {
+            val.dst_port = classifier.dst_port();
+            val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT;
+        }
+
+        if (!classifier.pkt_tag_type().empty()) {
+            if (classifier.pkt_tag_type().compare("untagged") == 0) {
+                val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED;
+                val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
+            } else if (classifier.pkt_tag_type().compare("single_tag") == 0) {
+                val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG;
+                val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
+            } else if (classifier.pkt_tag_type().compare("double_tag") == 0) {
+                val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG;
+                val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE;
+            }
+        }
+
+        BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val);
+    }
+
+    {
+        bcmbal_action val = { };
+
+        const ::openolt::ActionCmd& cmd = action.cmd();
+
+        if (cmd.add_outer_tag()) {
+            val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG;
+            val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
+        }
+
+        if (cmd.remove_outer_tag()) {
+            val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG;
+            val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
+        }
+
+        if (cmd.trap_to_host()) {
+            val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST;
+            val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK;
+        }
+
+        if (action.o_vid()) {
+            val.o_vid = action.o_vid();
+            val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID;
+        }
+
+        if (action.o_pbits()) {
+            val.o_pbits = action.o_pbits();
+            val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS;
+        }
+
+        if (action.o_tpid()) {
+            val.o_tpid = action.o_tpid();
+            val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID;
+        }
+
+        if (action.i_vid()) {
+            val.i_vid = action.i_vid();
+            val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID;
+        }
+
+        if (action.i_pbits()) {
+            val.i_pbits = action.i_pbits();
+            val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS;
+        }
+
+        if (action.i_tpid()) {
+            val.i_tpid = action.i_tpid();
+            val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID;
+        }
+
+        BCMBAL_CFG_PROP_SET(&cfg, flow, action, val);
+    }
+
+    {
+        bcmbal_tm_sched_id val;
+        val = (bcmbal_tm_sched_id) mk_sched_id(onu_id);
+        BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val);
+    }
+
+    if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr))) {
+        std::cout << "ERROR: flow add failed" << std::endl;
+        return Status(grpc::StatusCode::INTERNAL, "flow add failed");
+    }
+
+    return Status::OK;
+}
+
+Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) {
+    bcmbal_tm_sched_cfg cfg;
+    bcmbal_tm_sched_key key = { };
+    bcmbal_tm_sched_type sched_type;
+
+    key.id = mk_sched_id(onu_id);
+    key.dir = BCMBAL_TM_SCHED_DIR_US;
+
+    BCMBAL_CFG_INIT(&cfg, tm_sched, key);
+
+    {
+        bcmbal_tm_sched_owner val = { };
+
+        val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT;
+        val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id;
+	val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_INTF_ID;
+        val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id;
+        val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_SUB_TERM_ID;
+
+	val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id;
+	val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_AGG_PORT_ID;
+
+        BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val);
+    }
+
+    if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr))) {
+        std::cout << "ERROR: Failed to create upstream DBA sched"
+                  << " id:" << key.id
+                  << " intf_id:" << intf_id
+                  << " onu_id:" << onu_id << std::endl;
+        return Status(grpc::StatusCode::INTERNAL, "Failed to create upstream DBA sched");
+        //return 1;
+    }
+    std::cout << "create upstream DBA sched"
+              << " id:" << key.id
+              << " intf_id:" << intf_id
+              << " onu_id:" << onu_id << std::endl;
+
+    return Status::OK;
+    //return 0;
+}
diff --git a/src/server.h b/src/server.h
new file mode 100644
index 0000000..6e73d47
--- /dev/null
+++ b/src/server.h
@@ -0,0 +1,48 @@
+/*
+    Copyright (C) 2018 Open Networking Foundation 
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef OPENASF_SERVER_H_
+#define OPENASF_SERVER_H_
+
+#include <grpc++/grpc++.h>
+using grpc::Status;
+#include <openolt.grpc.pb.h>
+
+void RunServer();
+Status Enable_();
+Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
+    const char *vendor_id, const char *vendor_specific);
+Status EnablePonIf_(uint32_t intf_id);
+Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt);
+Status FlowAdd_(uint32_t onu_id,
+                uint32_t flow_id, const std::string flow_type,
+                uint32_t access_intf_id, uint32_t network_intf_id,
+                uint32_t gemport_id,
+                const ::openolt::Classifier& classifier,
+                const ::openolt::Action& action);
+
+static Status SchedAdd_(int intf_id, int onu_id, int agg_port_id);
+
+static inline int mk_sched_id(int onu_id) {
+    return 1023 + onu_id;
+}
+
+static inline int mk_agg_port_id(int onu_id) {
+    return 1023 + onu_id;
+}
+
+#endif
diff --git a/src/server.o b/src/server.o
new file mode 100644
index 0000000..a814ddc
--- /dev/null
+++ b/src/server.o
Binary files differ
diff --git a/src/utils.cc b/src/utils.cc
new file mode 100644
index 0000000..9610cdc
--- /dev/null
+++ b/src/utils.cc
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2018 Open Networking Foundation 
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "utils.h"
+
+// NOTE - This function is not thread-safe.
+const char* serial_number_to_str(bcmbal_serial_number* serial_number) {
+#define SERIAL_NUMBER_SIZE 12
+    static char buff[SERIAL_NUMBER_SIZE+1];
+
+    sprintf(buff, "%c%c%c%c%1X%1X%1X%1X%1X%1X%1X%1X",
+            serial_number->vendor_id[0],
+            serial_number->vendor_id[1],
+            serial_number->vendor_id[2],
+            serial_number->vendor_id[3],
+            serial_number->vendor_specific[0]>>4 & 0x0f,
+            serial_number->vendor_specific[0] & 0x0f,
+            serial_number->vendor_specific[1]>>4 & 0x0f,
+            serial_number->vendor_specific[1] & 0x0f,
+            serial_number->vendor_specific[2]>>4 & 0x0f,
+            serial_number->vendor_specific[2] & 0x0f,
+            serial_number->vendor_specific[3]>>4 & 0x0f,
+            serial_number->vendor_specific[3] & 0x0f);
+
+    return buff;
+}
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..a79bd55
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,30 @@
+/*
+    Copyright (C) 2018 Open Networking Foundation
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef OPENASF_UTILS_H_
+#define OPENASF_UTILS_H_
+
+extern "C"
+{
+#include <bcmos_system.h>
+#include <bal_api.h>
+#include <bal_api_end.h>
+}
+
+const char* serial_number_to_str(bcmbal_serial_number* serial_number);
+
+#endif
diff --git a/src/utils.o b/src/utils.o
new file mode 100644
index 0000000..323222c
--- /dev/null
+++ b/src/utils.o
Binary files differ