blob: 91fcfac494b71943453b8f1f6dd65ae03dbca2a1 [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 = {};
52 bcmbal_registration_id registration_id = {};
53 int has_serial_num = BCMOS_FALSE;
54 int has_registration_id = BCMOS_FALSE;
55 char two_digit_buf[3];
56
57 two_digit_buf[2] = 0;
58
Kim Kempfafa1ab42017-11-13 09:31:47 -080059 ASFVOLT_LOG(ASFVOLT_DEBUG, "Before encoding,Vendor Id(%s),Vendor Specific Id(%s), Registration Id(%s)",
60 onu_cfg->data->serial_number->vendor_id,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053061 onu_cfg->data->serial_number->vendor_specific,
62 onu_cfg->data->registration_id);
63
64 char vendor_id[20];
65 memset(&vendor_id, 0, 20);
66 sprintf(vendor_id,"%2X%2X%2X%2X",
67 onu_cfg->data->serial_number->vendor_id[0],
68 onu_cfg->data->serial_number->vendor_id[1],
69 onu_cfg->data->serial_number->vendor_id[2],
70 onu_cfg->data->serial_number->vendor_id[3]);
71 onu_cfg->data->serial_number->vendor_id = vendor_id;
Kim Kempfafa1ab42017-11-13 09:31:47 -080072 ASFVOLT_LOG(ASFVOLT_DEBUG, "After encoding,Vendor Id(%s),Vendor Specific Id(%s), Registration Id(%s)",
73 onu_cfg->data->serial_number->vendor_id,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053074 onu_cfg->data->serial_number->vendor_specific,
75 onu_cfg->data->registration_id);
76
77 /* Vendor Id is totally 16 byte string and should be
78 send in hexadecimmal format */
79 for(idx=0; idx<2*sizeof(serial_num.vendor_id); idx+=2)
80 {
81 memcpy(two_digit_buf, &onu_cfg->data->serial_number->vendor_id[idx], 2);
82 serial_num.vendor_id[idx>>1] = strtol(two_digit_buf, NULL, 16);
83 has_serial_num = BCMOS_TRUE;
84 }
85 for(idx=0; idx<2*sizeof(serial_num.vendor_specific); idx+=2)
86 {
87 memcpy(two_digit_buf, &onu_cfg->data->serial_number->vendor_specific[idx], 2);
88 serial_num.vendor_specific[idx>>1] = strtol(two_digit_buf, NULL, 16);
89 }
90
91 ASFVOLT_CFG_PROP_SET(sub_term_obj, subscriber_terminal, serial_number,
92 has_serial_num, serial_num);
93
94 /* Registration ID is a string and should be given in hexadecimal format */
95 for(idx=0; idx<strlen(onu_cfg->data->registration_id) && idx<2*sizeof(registration_id.arr); idx+=2)
96 {
97 memcpy(two_digit_buf, &onu_cfg->data->registration_id[idx], 2);
98 registration_id.arr[idx>>1] = strtol(two_digit_buf, NULL, 16);
99 has_registration_id = BCMOS_TRUE;
100 }
101
102 ASFVOLT_CFG_PROP_SET(sub_term_obj, subscriber_terminal, registration_id,
103 has_registration_id, registration_id);
104
105 if (!memcmp(&serial_num, &zero_serial_num, sizeof(serial_num)))
106 skip_onu = BCMOS_TRUE;
107 }
108
109 ASFVOLT_CFG_PROP_SET(sub_term_obj, subscriber_terminal, admin_state,
Girish Gowdru50278de2017-11-23 12:35:41 +0530110 BCMOS_TRUE, onu_cfg->data->admin_state);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530111
112 if (!skip_onu)
113 {
114
Kim Kempfafa1ab42017-11-13 09:31:47 -0800115 /*ASFVOLT_LOG(ASFVOLT_DEBUG, "Onu's(%d) Serial number %02x%02x%02x%2x%02x%02x%02x%02x",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530116 onu_cfg->key->sub_term_id,
117 sub_term_obj.data->serial_number.vendor_id[0], sub_term_obj.data->serial_number.vendor_id[1],
118 sub_term_obj.data->serial_number.vendor_id[2], sub_term_obj.data->serial_number.vendor_id[3],
119 sub_term_obj.data->serial_number.vendor_specific[0], sub_term_obj.data->serial_number.vendor_specific[1],
120 sub_term_obj.data->serial_number.vendor_specific[2], sub_term_obj.data->serial_number.vendor_specific[3]);*/
121
122 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr));
123
Kim Kempfafa1ab42017-11-13 09:31:47 -0800124 ASFVOLT_LOG(ASFVOLT_DEBUG,
125 "....SENT SUBSCRIBER TERMINAL %sUP %d on interface %d...",
126 (BCM_ERR_OK != err) ? "NOT " : "",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530127 subs_terminal_key.sub_term_id,
128 subs_terminal_key.intf_id);
129 }
130 else
131 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800132 ASFVOLT_LOG(ASFVOLT_DEBUG,
133 "Skipping activation of subscriber terminal %d on interface %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530134 subs_terminal_key.sub_term_id,
135 subs_terminal_key.intf_id);
136 err = BAL_ERRNO__BAL_ERR_PARM;
137 }
138
139 return BAL_ERRNO__BAL_ERR_OK;
140}
141
142
143/********************************************************************\
144 * Function : bal_subscriber_terminal_indication_cb *
145 * Description : Call Back indication registered with BAL to handle *
146 * events related to subscriber terminal(ONU) *
147 ********************************************************************/
148bcmos_errno bal_subscriber_terminal_indication_cb(bcmbal_obj *obj)
149{
150 bcmos_errno result = BCM_ERR_OK;
151
152#if 0
153 bcmbal_subscriber_terminal_cfg *cfg = ((bcmbal_subscriber_terminal_cfg *)obj);
154
155 if(BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL == obj->obj_type)
156 {
157 bcmbal_serial_number *p_serial_number =
158 (((bcmbal_subscriber_terminal_cfg *)obj)->data->serial_number);
159
160 if(BCMBAL_SUB_ID_UNKNOWN == (((bcmbal_subscriber_terminal_cfg *)obj)->key.sub_term_id))
161 {
162 ASFVOLT_LOG(ASFVOLT_INFO, "New ONU Discovered. serial number "
163 "%2X%2X%2X%2X%1X%1X%1X%1X%1X%1X%1X%1X "
Kim Kempfafa1ab42017-11-13 09:31:47 -0800164 "on PON %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530165 p_serial_number->vendor_id[0],
166 p_serial_number->vendor_id[1],
167 p_serial_number->vendor_id[2],
168 p_serial_number->vendor_id[3],
169 p_serial_number->vendor_specific[0]>>4 & 0x0f,
170 p_serial_number->vendor_specific[0] & 0x0f,
171 p_serial_number->vendor_specific[1]>>4 & 0x0f,
172 p_serial_number->vendor_specific[1] & 0x0f,
173 p_serial_number->vendor_specific[2]>>4 & 0x0f,
174 p_serial_number->vendor_specific[2] & 0x0f,
175 p_serial_number->vendor_specific[3]>>4 & 0x0f,
176 p_serial_number->vendor_specific[3] & 0x0f,
177
178 ((bcmbal_subscriber_terminal_cfg *)obj)->key.intf_id);
179
180 }
181 else
182 {
183 ASFVOLT_LOG(ASFVOLT_INFO, "Event on existing ONU. serial number "
184 "%2X%2X%2X%2X%1X%1X%1X%1X%1X%1X%1X%1X "
Kim Kempfafa1ab42017-11-13 09:31:47 -0800185 "on PON %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530186 p_serial_number->vendor_id[0],
187 p_serial_number->vendor_id[1],
188 p_serial_number->vendor_id[2],
189 p_serial_number->vendor_id[3],
190 p_serial_number->vendor_specific[0]>>4 & 0x0f,
191 p_serial_number->vendor_specific[0] & 0x0f,
192 p_serial_number->vendor_specific[1]>>4 & 0x0f,
193 p_serial_number->vendor_specific[1] & 0x0f,
194 p_serial_number->vendor_specific[2]>>4 & 0x0f,
195 p_serial_number->vendor_specific[2] & 0x0f,
196 p_serial_number->vendor_specific[3]>>4 & 0x0f,
197 p_serial_number->vendor_specific[3] & 0x0f,
198
199 ((bcmbal_subscriber_terminal_cfg *)obj)->key.intf_id);
200
201 }
202 }
203 else
204 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800205 ASFVOLT_LOG(ASFVOLT_ERROR,
206 "Invalid object type %d for subscriber terminal indication",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530207 obj->obj_type);
Kim Kempfafa1ab42017-11-13 09:31:47 -0800208
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530209 }
210
211#endif
212 return result;
213}
214
215/********************************************************************\
216 * Function : bal_subscriber_terminal_cfg_clear *
217 * Description : clears the subscriber terminal(ONU) configuration *
218 ********************************************************************/
219uint32_t bal_subscriber_terminal_cfg_clear(BalSubscriberTerminalKey *terminal_key)
220{
221 bcmos_errno err = BCM_ERR_OK;
222 bcmbal_subscriber_terminal_cfg cfg;
223 bcmbal_subscriber_terminal_key key = { };
224
Suhas Gururajbc53a352018-01-17 21:34:58 +0530225 ASFVOLT_LOG(ASFVOLT_INFO, "Processing subscriber terminal cfg clear for sub_term_id = %d and intf_id = %d",
226 terminal_key->sub_term_id,
227 terminal_key->intf_id);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530228
Suhas Gururajbc53a352018-01-17 21:34:58 +0530229 key.sub_term_id = terminal_key->sub_term_id ;
230 key.intf_id = terminal_key->intf_id ;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800231
Suhas Gururajbc53a352018-01-17 21:34:58 +0530232 if (0 == key.sub_term_id)
233 {
234 ASFVOLT_LOG(ASFVOLT_ERROR,
235 "Invalid Key to handle subscriber terminal clear subscriber_terminal_id(%d), Interface ID(%d)",
236 key.sub_term_id, key.intf_id);
237 return BAL_ERRNO__BAL_ERR_PARM;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530238 }
239
Suhas Gururajbc53a352018-01-17 21:34:58 +0530240 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
241
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530242 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
Suhas Gururajbc53a352018-01-17 21:34:58 +0530243 if (err != BCM_ERR_OK)
244 {
245 ASFVOLT_LOG(ASFVOLT_ERROR,
246 "Failed to clear information for BAL subscriber_terminal_id(%d), Interface ID(%d)",
247 key.sub_term_id, key.intf_id);
248 return BAL_ERRNO__BAL_ERR_INTERNAL;
249 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530250 err = BAL_ERRNO__BAL_ERR_OK;
251 return err;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800252}
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530253
254/********************************************************************\
255 * Function : bal_subscriber_terminal_cfg_get *
256 * Description : Get the subscriber terminal(ONU) configuration *
257 ********************************************************************/
Kim Kempfafa1ab42017-11-13 09:31:47 -0800258uint32_t bal_subscriber_terminal_cfg_get(BalSubscriberTerminalKey *terminal_key,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530259 BalSubscriberTerminalCfg *onu_cfg)
260{
261
262 bcmos_errno err = BCM_ERR_OK;
263 bcmbal_subscriber_terminal_cfg cfg; /**< declare main API struct */
264 bcmbal_subscriber_terminal_key key = { }; /**< declare key */
265 uint8_t *list_mem; /**< declare memory buffer for variable-sized lists */
266
Kim Kempfafa1ab42017-11-13 09:31:47 -0800267 ASFVOLT_LOG(ASFVOLT_INFO,
268 "Processing subscriber terminal cfg get: %d",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530269 onu_cfg->key->sub_term_id);
270
Kim Kempfafa1ab42017-11-13 09:31:47 -0800271 if (terminal_key->has_sub_term_id &&
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530272 terminal_key->has_intf_id)
273 {
274 key.sub_term_id = terminal_key->sub_term_id ;
275 key.intf_id = terminal_key->intf_id ;
276 }
277 else
278 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800279 ASFVOLT_LOG(ASFVOLT_ERROR,
280 "Invalid Key to handle subscriber terminal Cfg Get subscriber_terminal_id(%d), Interface ID(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530281 key.sub_term_id, key.intf_id);
Kim Kempfafa1ab42017-11-13 09:31:47 -0800282
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530283 return BAL_ERRNO__BAL_ERR_PARM;
284 }
285
286 /* init the API struct */
287 BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key);
288
289 BCMBAL_CFG_PROP_GET(&cfg, subscriber_terminal, all_properties);
290
291 /* set memory to use for variable-sized lists */
292 list_mem = malloc(BAL_DYNAMIC_LIST_BUFFER_SIZE);
293 if (list_mem == NULL)
294 {
295
Kim Kempfafa1ab42017-11-13 09:31:47 -0800296 ASFVOLT_LOG(ASFVOLT_ERROR,
297 "Memory allocation failed while handling subscriber terminal cfg get subscriber_terminal_id(%d), Interface ID(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530298 key.sub_term_id, key.intf_id);
299 return BAL_ERRNO__BAL_ERR_NOMEM;
300 }
301
302 memset(list_mem, 0, BAL_DYNAMIC_LIST_BUFFER_SIZE);
303 BCMBAL_CFG_LIST_BUF_SET(&cfg, subscriber_terminal, list_mem, BAL_DYNAMIC_LIST_BUFFER_SIZE);
304
305 /* call API */
306 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &cfg.hdr);
307 if (err != BCM_ERR_OK)
308 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800309 ASFVOLT_LOG(ASFVOLT_ERROR,
310 "Failed to get information from BAL subscriber_terminal_id(%d), Interface ID(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530311 key.sub_term_id, key.intf_id);
312 return BAL_ERRNO__BAL_ERR_INTERNAL;
313 }
314
Kim Kempfafa1ab42017-11-13 09:31:47 -0800315 ASFVOLT_LOG(ASFVOLT_INFO,
316 "To-Do. Send subscriber terminal details to Adapter");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530317 return BAL_ERRNO__BAL_ERR_OK;
318}