blob: 42dccc26bffddad4668afd28aaffbe99ca6ffa49 [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#include "asfvolt16_driver.h"
23#include "bal_subscriber_terminal_hdlr.h"
24
25/********************************************************************\
26 * Function : bal_subscriber_terminal_cfg_set *
27 * Description : Configures the subscriber terminal(ONU) *
28 ********************************************************************/
29uint32_t bal_subscriber_terminal_cfg_set(BalSubscriberTerminalCfg *onu_cfg)
30{
31
32 bcmos_errno err = BCM_ERR_OK;
33 bcmbal_subscriber_terminal_cfg sub_term_obj = {};
34 bcmbal_subscriber_terminal_key subs_terminal_key;
35 bcmos_bool skip_onu = BCMOS_FALSE;
36
Kim Kempfb032b672017-09-11 18:40:34 -070037 size_t idx;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053038
39 subs_terminal_key.sub_term_id = onu_cfg->key->sub_term_id;
40 subs_terminal_key.intf_id = onu_cfg->key->intf_id;
41
Kim Kempfafa1ab42017-11-13 09:31:47 -080042 ASFVOLT_LOG(ASFVOLT_INFO, "Bringing up the subscriber terminal: %d", onu_cfg->key->sub_term_id);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053043
44 /*
45 * Set the key in the subscriber terminal object
46 */
47 BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key);
48
49 {
50 bcmbal_serial_number serial_num = {} ;
51 bcmbal_serial_number zero_serial_num = {};
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053052 int has_serial_num = BCMOS_FALSE;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053053 char two_digit_buf[3];
54
55 two_digit_buf[2] = 0;
56
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053057 char vendor_id[20];
58 memset(&vendor_id, 0, 20);
59 sprintf(vendor_id,"%2X%2X%2X%2X",
60 onu_cfg->data->serial_number->vendor_id[0],
61 onu_cfg->data->serial_number->vendor_id[1],
62 onu_cfg->data->serial_number->vendor_id[2],
63 onu_cfg->data->serial_number->vendor_id[3]);
64 onu_cfg->data->serial_number->vendor_id = vendor_id;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053065 /* Vendor Id is totally 16 byte string and should be
66 send in hexadecimmal format */
67 for(idx=0; idx<2*sizeof(serial_num.vendor_id); idx+=2)
68 {
69 memcpy(two_digit_buf, &onu_cfg->data->serial_number->vendor_id[idx], 2);
70 serial_num.vendor_id[idx>>1] = strtol(two_digit_buf, NULL, 16);
71 has_serial_num = BCMOS_TRUE;
72 }
73 for(idx=0; idx<2*sizeof(serial_num.vendor_specific); idx+=2)
74 {
75 memcpy(two_digit_buf, &onu_cfg->data->serial_number->vendor_specific[idx], 2);
76 serial_num.vendor_specific[idx>>1] = strtol(two_digit_buf, NULL, 16);
77 }
78
79 ASFVOLT_CFG_PROP_SET(sub_term_obj, subscriber_terminal, serial_number,
80 has_serial_num, serial_num);
81
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053082 if (!memcmp(&serial_num, &zero_serial_num, sizeof(serial_num)))
83 skip_onu = BCMOS_TRUE;
84 }
85
86 ASFVOLT_CFG_PROP_SET(sub_term_obj, subscriber_terminal, admin_state,
Girish Gowdru50278de2017-11-23 12:35:41 +053087 BCMOS_TRUE, onu_cfg->data->admin_state);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053088
89 if (!skip_onu)
90 {
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053091 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
92
Kim Kempfafa1ab42017-11-13 09:31:47 -080093 ASFVOLT_LOG(ASFVOLT_DEBUG,
94 "....SENT SUBSCRIBER TERMINAL %sUP %d on interface %d...",
95 (BCM_ERR_OK != err) ? "NOT " : "",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053096 subs_terminal_key.sub_term_id,
97 subs_terminal_key.intf_id);
98 }
99 else
100 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800101 ASFVOLT_LOG(ASFVOLT_DEBUG,
102 "Skipping activation of subscriber terminal %d on interface %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530103 subs_terminal_key.sub_term_id,
104 subs_terminal_key.intf_id);
105 err = BAL_ERRNO__BAL_ERR_PARM;
106 }
107
108 return BAL_ERRNO__BAL_ERR_OK;
109}
110
111
112/********************************************************************\
113 * Function : bal_subscriber_terminal_indication_cb *
114 * Description : Call Back indication registered with BAL to handle *
115 * events related to subscriber terminal(ONU) *
116 ********************************************************************/
117bcmos_errno bal_subscriber_terminal_indication_cb(bcmbal_obj *obj)
118{
119 bcmos_errno result = BCM_ERR_OK;
120
121#if 0
122 bcmbal_subscriber_terminal_cfg *cfg = ((bcmbal_subscriber_terminal_cfg *)obj);
123
124 if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL == obj->obj_type)
125 {
126 bcmbal_serial_number *p_serial_number =
127 (((bcmbal_subscriber_terminal_cfg *)obj)->data->serial_number);
128
129 if(BCMBAL_SUB_ID_UNKNOWN == (((bcmbal_subscriber_terminal_cfg *)obj)->key.sub_term_id))
130 {
131 ASFVOLT_LOG(ASFVOLT_INFO, "New ONU Discovered. serial number "
132 "%2X%2X%2X%2X%1X%1X%1X%1X%1X%1X%1X%1X "
Kim Kempfafa1ab42017-11-13 09:31:47 -0800133 "on PON %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530134 p_serial_number->vendor_id[0],
135 p_serial_number->vendor_id[1],
136 p_serial_number->vendor_id[2],
137 p_serial_number->vendor_id[3],
138 p_serial_number->vendor_specific[0]>>4 & 0x0f,
139 p_serial_number->vendor_specific[0] & 0x0f,
140 p_serial_number->vendor_specific[1]>>4 & 0x0f,
141 p_serial_number->vendor_specific[1] & 0x0f,
142 p_serial_number->vendor_specific[2]>>4 & 0x0f,
143 p_serial_number->vendor_specific[2] & 0x0f,
144 p_serial_number->vendor_specific[3]>>4 & 0x0f,
145 p_serial_number->vendor_specific[3] & 0x0f,
146
147 ((bcmbal_subscriber_terminal_cfg *)obj)->key.intf_id);
148
149 }
150 else
151 {
152 ASFVOLT_LOG(ASFVOLT_INFO, "Event on existing ONU. serial number "
153 "%2X%2X%2X%2X%1X%1X%1X%1X%1X%1X%1X%1X "
Kim Kempfafa1ab42017-11-13 09:31:47 -0800154 "on PON %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530155 p_serial_number->vendor_id[0],
156 p_serial_number->vendor_id[1],
157 p_serial_number->vendor_id[2],
158 p_serial_number->vendor_id[3],
159 p_serial_number->vendor_specific[0]>>4 & 0x0f,
160 p_serial_number->vendor_specific[0] & 0x0f,
161 p_serial_number->vendor_specific[1]>>4 & 0x0f,
162 p_serial_number->vendor_specific[1] & 0x0f,
163 p_serial_number->vendor_specific[2]>>4 & 0x0f,
164 p_serial_number->vendor_specific[2] & 0x0f,
165 p_serial_number->vendor_specific[3]>>4 & 0x0f,
166 p_serial_number->vendor_specific[3] & 0x0f,
167
168 ((bcmbal_subscriber_terminal_cfg *)obj)->key.intf_id);
169
170 }
171 }
172 else
173 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800174 ASFVOLT_LOG(ASFVOLT_ERROR,
175 "Invalid object type %d for subscriber terminal indication",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530176 obj->obj_type);
Kim Kempfafa1ab42017-11-13 09:31:47 -0800177
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530178 }
179
180#endif
181 return result;
182}
183
184/********************************************************************\
185 * Function : bal_subscriber_terminal_cfg_clear *
186 * Description : clears the subscriber terminal(ONU) configuration *
187 ********************************************************************/
188uint32_t bal_subscriber_terminal_cfg_clear(BalSubscriberTerminalKey *terminal_key)
189{
190 bcmos_errno err = BCM_ERR_OK;
191 bcmbal_subscriber_terminal_cfg cfg;
192 bcmbal_subscriber_terminal_key key = { };
193
Suhas Gururajbc53a352018-01-17 21:34:58 +0530194 ASFVOLT_LOG(ASFVOLT_INFO, "Processing subscriber terminal cfg clear for sub_term_id = %d and intf_id = %d",
195 terminal_key->sub_term_id,
196 terminal_key->intf_id);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530197
Suhas Gururajbc53a352018-01-17 21:34:58 +0530198 key.sub_term_id = terminal_key->sub_term_id ;
199 key.intf_id = terminal_key->intf_id ;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800200
Suhas Gururajbc53a352018-01-17 21:34:58 +0530201 if (0 == key.sub_term_id)
202 {
203 ASFVOLT_LOG(ASFVOLT_ERROR,
204 "Invalid Key to handle subscriber terminal clear subscriber_terminal_id(%d), Interface ID(%d)",
205 key.sub_term_id, key.intf_id);
206 return BAL_ERRNO__BAL_ERR_PARM;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530207 }
208
Suhas Gururajbc53a352018-01-17 21:34:58 +0530209 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
210
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530211 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
Suhas Gururajbc53a352018-01-17 21:34:58 +0530212 if (err != BCM_ERR_OK)
213 {
214 ASFVOLT_LOG(ASFVOLT_ERROR,
215 "Failed to clear information for BAL subscriber_terminal_id(%d), Interface ID(%d)",
216 key.sub_term_id, key.intf_id);
217 return BAL_ERRNO__BAL_ERR_INTERNAL;
218 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530219 err = BAL_ERRNO__BAL_ERR_OK;
220 return err;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800221}
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530222
223/********************************************************************\
224 * Function : bal_subscriber_terminal_cfg_get *
225 * Description : Get the subscriber terminal(ONU) configuration *
226 ********************************************************************/
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700227uint32_t bal_subscriber_terminal_cfg_get(BalSubscriberTerminalCfg *onu_cfg)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530228{
229
230 bcmos_errno err = BCM_ERR_OK;
231 bcmbal_subscriber_terminal_cfg cfg; /**< declare main API struct */
232 bcmbal_subscriber_terminal_key key = { }; /**< declare key */
233 uint8_t *list_mem; /**< declare memory buffer for variable-sized lists */
234
Kim Kempfafa1ab42017-11-13 09:31:47 -0800235 ASFVOLT_LOG(ASFVOLT_INFO,
236 "Processing subscriber terminal cfg get: %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530237 onu_cfg->key->sub_term_id);
238
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700239 key.sub_term_id = onu_cfg->key->sub_term_id ;
240 key.intf_id = onu_cfg->key->intf_id ;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530241
242 /* init the API struct */
243 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
244
245 BCMBAL_CFG_PROP_GET(&cfg, subscriber_terminal, all_properties);
246
247 /* set memory to use for variable-sized lists */
248 list_mem = malloc(BAL_DYNAMIC_LIST_BUFFER_SIZE);
249 if (list_mem == NULL)
250 {
251
Kim Kempfafa1ab42017-11-13 09:31:47 -0800252 ASFVOLT_LOG(ASFVOLT_ERROR,
253 "Memory allocation failed while handling subscriber terminal cfg get subscriber_terminal_id(%d), Interface ID(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530254 key.sub_term_id, key.intf_id);
255 return BAL_ERRNO__BAL_ERR_NOMEM;
256 }
257
258 memset(list_mem, 0, BAL_DYNAMIC_LIST_BUFFER_SIZE);
259 BCMBAL_CFG_LIST_BUF_SET(&cfg, subscriber_terminal, list_mem, BAL_DYNAMIC_LIST_BUFFER_SIZE);
260
261 /* call API */
262 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &cfg.hdr);
263 if (err != BCM_ERR_OK)
264 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800265 ASFVOLT_LOG(ASFVOLT_ERROR,
266 "Failed to get information from BAL subscriber_terminal_id(%d), Interface ID(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530267 key.sub_term_id, key.intf_id);
268 return BAL_ERRNO__BAL_ERR_INTERNAL;
269 }
270
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700271 ASFVOLT_LOG(ASFVOLT_INFO, "Get Subscriber cfg sent to OLT for Subscriber Id(%d) on Interface(%d)",
272 key.sub_term_id, key.intf_id);
273
274 onu_cfg->key->has_sub_term_id = BAL_ELEMENT_PRES;
275 onu_cfg->key->sub_term_id = cfg.key.sub_term_id;
276
277 onu_cfg->key->has_intf_id = BAL_ELEMENT_PRES;
278 onu_cfg->key->intf_id = cfg.key.intf_id;
279
280 onu_cfg->data->has_admin_state = BAL_ELEMENT_PRES;
281 onu_cfg->data->admin_state = cfg.data.admin_state;
282
283 onu_cfg->data->has_oper_status = BAL_ELEMENT_PRES;
284 onu_cfg->data->oper_status = cfg.data.oper_status;
285
286 onu_cfg->data->has_svc_port_id = BAL_ELEMENT_PRES;
287 onu_cfg->data->svc_port_id = cfg.data.svc_port_id;
288
289 onu_cfg->data->has_ds_tm = BAL_ELEMENT_PRES;
290 onu_cfg->data->ds_tm = cfg.data.ds_tm;
291
292 onu_cfg->data->has_us_tm = BAL_ELEMENT_PRES;
293 onu_cfg->data->us_tm = cfg.data.us_tm;
294
295 onu_cfg->data->has_sub_term_rate = BAL_ELEMENT_PRES;
296 onu_cfg->data->sub_term_rate = cfg.data.sub_term_rate;
297
298 char *password = malloc(sizeof(char)*MAX_CHAR_LENGTH*2);
299 memset(password, 0, MAX_CHAR_LENGTH*2);
300 strcpy(password,(const char *)cfg.data.password.arr);
301 onu_cfg->data->password = password;
302
303 char *registration_id = malloc(sizeof(char)*MAX_REGID_LENGTH);
304 memset(registration_id, 0, MAX_REGID_LENGTH);
305 strcpy(registration_id,(const char *)cfg.data.registration_id.arr);
306 onu_cfg->data->registration_id = registration_id;
307
308 BalSerialNumber *serialNum;
309 serialNum = malloc(sizeof(BalSerialNumber));
310 memset(serialNum, 0, sizeof(BalSerialNumber));
311 bal_serial_number__init(serialNum);
312 onu_cfg->data->serial_number = serialNum;
313
314 char *vendor_id = malloc(sizeof(char)*MAX_CHAR_LENGTH);
315 memset(vendor_id, 0, MAX_CHAR_LENGTH);
316 sprintf(vendor_id,"%c%c%c%c",
317 cfg.data.serial_number.vendor_id[0],
318 cfg.data.serial_number.vendor_id[1],
319 cfg.data.serial_number.vendor_id[2],
320 cfg.data.serial_number.vendor_id[3]);
321
322 onu_cfg->data->serial_number->vendor_id = vendor_id;
323
324 char *vendor_specific = malloc(sizeof(char)*MAX_CHAR_LENGTH);
325 memset(vendor_specific, 0, MAX_CHAR_LENGTH);
326 sprintf(vendor_specific,"%1X%1X%1X%1X%1X%1X%1X%1X",
327 cfg.data.serial_number.vendor_specific[0]>>4 & 0x0f,
328 cfg.data.serial_number.vendor_specific[0] & 0x0f,
329 cfg.data.serial_number.vendor_specific[1]>>4 & 0x0f,
330 cfg.data.serial_number.vendor_specific[1] & 0x0f,
331 cfg.data.serial_number.vendor_specific[2]>>4 & 0x0f,
332 cfg.data.serial_number.vendor_specific[2] & 0x0f,
333 cfg.data.serial_number.vendor_specific[3]>>4 & 0x0f,
334 cfg.data.serial_number.vendor_specific[3] & 0x0f);
335 onu_cfg->data->serial_number->vendor_specific = vendor_specific;
336
337 free(list_mem);
338
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530339 return BAL_ERRNO__BAL_ERR_OK;
340}