blob: 5f01c1dce21ccaed22915d2b2e226785fa14fc9d [file] [log] [blame]
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301/*
2** Copyright 2017-present Open Networking Foundation
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8** http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
17#include <stdio.h>
18#include <bal_api.h>
19
20#undef _SYS_QUEUE_H_
21
22/* Includes related to proto buf */
23#include "bal_msg_type.grpc-c.h"
24#include "bal_osmsg.grpc-c.h"
25#include "bal_model_ids.grpc-c.h"
26#include "bal_obj.grpc-c.h"
27#include "bal_model_types.grpc-c.h"
28#include "bal_errno.grpc-c.h"
29#include "bal.grpc-c.h"
30
31#include "asfvolt16_driver.h"
32#include "bal_packet_hdlr.h"
Rajeswara Raob2e441c2017-09-20 16:40:21 +053033static bcmos_mutex bal_ind_lock;
34
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053035
36/********************************************************************\
37 * Function : bal_access_terminal_cfg_req *
38 * Description : Configures the PON and NNI interfaces *
39 * of OLT Device *
40 ********************************************************************/
41uint32_t bal_packet_cfg_req(BalPacketCfg *packet)
42{
Rajeswara Raob2e441c2017-09-20 16:40:21 +053043 bcmos_mutex_lock(&bal_ind_lock);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053044 bcmos_errno err = BCM_ERR_OK;
Rajeswara Raob2e441c2017-09-20 16:40:21 +053045 bcmbal_access_term_id aterm_id = 0; /* Assume a single access_terminal instance */
46 bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053047 switch(packet->key->packet_send_dest->type)
48 {
49 case BAL_DEST_TYPE__BAL_DEST_TYPE_NNI:
50 {
Rajeswara Raob2e441c2017-09-20 16:40:21 +053051 bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_NNI,
52 .u.nni.intf_id = packet->key->packet_send_dest->nni->intf_id };
53 buf.len = packet->data->pkt.len;
54 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
55 memcpy(buf.val,(uint8_t *)packet->data->pkt.data,buf.len);
56 ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Packet of length %d bytes with dest type as %d\n",buf.len,packet->key->packet_send_dest->type);
57 err = bcmbal_pkt_send(aterm_id,
58 proxy_pkt_dest,
59 (const char *)(buf.val),
60 buf.len);
61 free(buf.val);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053062 }
63 break;
64 case BAL_DEST_TYPE__BAL_DEST_TYPE_SUB_TERM:
65 {
Rajeswara Raob2e441c2017-09-20 16:40:21 +053066 bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_SUB_TERM,
67 .u.sub_term.sub_term_id = packet->key->packet_send_dest->sub_term->sub_term_id,
68 .u.sub_term.intf_id = packet->key->packet_send_dest->sub_term->intf_id };
69 buf.len = packet->data->pkt.len;
70 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
71 memcpy(buf.val,(uint8_t *)packet->data->pkt.data,buf.len);
72 ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Packet of length %d bytes with dest type as %d\n",buf.len,packet->key->packet_send_dest->type);
73 err = bcmbal_pkt_send(aterm_id,
74 proxy_pkt_dest,
75 (const char *)(buf.val),
76 buf.len);
77 free(buf.val);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053078 }
79 break;
80 case BAL_DEST_TYPE__BAL_DEST_TYPE_SVC_PORT:
81 {
Rajeswara Raob2e441c2017-09-20 16:40:21 +053082 bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_SVC_PORT,
83 .u.svc_port.svc_port_id = packet->key->packet_send_dest->svc_port->svc_port_id,
84 .u.svc_port.intf_id = packet->key->packet_send_dest->svc_port->intf_id };
85 buf.len = packet->data->pkt.len;
86 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
87 ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Packet of length %d bytes with dest type as %d\n",buf.len,packet->key->packet_send_dest->type);
88 memcpy(buf.val,(uint8_t *)packet->data->pkt.data,buf.len);
89 err = bcmbal_pkt_send(aterm_id,
90 proxy_pkt_dest,
91 (const char *)(buf.val),
92 buf.len);
93 free(buf.val);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053094 }
95 break;
96 case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL:
97 {
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053098 /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */
99 bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL,
100 .u.itu_omci_channel.sub_term_id = packet->key->packet_send_dest->itu_omci_channel->sub_term_id,
101 .u.itu_omci_channel.intf_id = packet->key->packet_send_dest->itu_omci_channel->intf_id };
102 buf.len = ((strlen((const char *)(packet->data->pkt.data))/2)) > MAX_OMCI_MSG_LENGTH ? MAX_OMCI_MSG_LENGTH : ((strlen((const char *)(packet->data->pkt.data))/2)); /* is the length of your OMCI message */
103 /* Send the OMCI packet using the BAL remote proxy API */
104 uint16_t idx1 = 0;
105 uint16_t idx2 = 0;
106 uint8_t arraySend[buf.len];
107 char str1[MAX_CHAR_LENGTH];
108 char str2[MAX_CHAR_LENGTH];
109 memset(&arraySend,0,buf.len);
110 ASFVOLT_LOG(ASFVOLT_DEBUG,"\nSending omci msg to ONU of length is %d\n",buf.len);
111 for(idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++)
112 {
113 sprintf(str1,"%c",packet->data->pkt.data[idx1]);
114 sprintf(str2,"%c",packet->data->pkt.data[++idx1]);
115 strcat(str1,str2);
116 arraySend[idx2] = strtol(str1, NULL, 16);
117 }
118 buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t));
119 memcpy(buf.val,(uint8_t *)arraySend,buf.len);
Rajeswara Raob2e441c2017-09-20 16:40:21 +0530120 ASFVOLT_LOG(ASFVOLT_DEBUG,"\nAfter converting it into hex ");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530121 for(idx2=0; idx2<buf.len; idx2++)
122 {
123 printf("%02x", buf.val[idx2]);
124 }
125 printf("\n");
126 err = bcmbal_pkt_send(aterm_id,
127 proxy_pkt_dest,
128 (const char *)(buf.val),
129 buf.len);
130 ASFVOLT_LOG(ASFVOLT_DEBUG, "\n OMCI request msg of length(%d) sent to ONU(%d) through PON(%d)\n",
131 buf.len,
132 packet->key->packet_send_dest->itu_omci_channel->sub_term_id,
133 packet->key->packet_send_dest->itu_omci_channel->intf_id);
Rajeswara Raob2e441c2017-09-20 16:40:21 +0530134 free(buf.val);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530135 }
136 break;
137 case BAL_DEST_TYPE__BAL_DEST_TYPE_IEEE_OAM_CHANNEL:
138 {
139 ASFVOLT_LOG(ASFVOLT_DEBUG, "\n PLOAM msg not yet implemented\n");
140 }
141 break;
142 default:
143 {
144 ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Invalid dest type\n");
145 }
146 break;
147 }
148 if (BCM_ERR_OK != err)
149 {
150 /* recover from any error encountered while sending */
151 }
Rajeswara Raob2e441c2017-09-20 16:40:21 +0530152 bcmos_mutex_unlock(&bal_ind_lock);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530153 return err;
154}