Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 1 | /* |
| 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 | ********************************************************************/ |
| 29 | uint32_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 | |
| 37 | int idx; |
| 38 | |
| 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 | |
| 42 | ASFVOLT_LOG(ASFVOLT_INFO, "Bringing up the subscriber terminal: %d\n", onu_cfg->key->sub_term_id); |
| 43 | |
| 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 | |
| 59 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Before encoding,Vendor Id(%s),Vendor Specific Id(%s), Registration Id(%s)\n", |
| 60 | onu_cfg->data->serial_number->vendor_id, |
| 61 | 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; |
| 72 | ASFVOLT_LOG(ASFVOLT_DEBUG, "After encoding,Vendor Id(%s),Vendor Specific Id(%s), Registration Id(%s)\n", |
| 73 | onu_cfg->data->serial_number->vendor_id, |
| 74 | 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, |
| 110 | BCMOS_TRUE, BCMBAL_STATE_UP); |
| 111 | |
| 112 | if (!skip_onu) |
| 113 | { |
| 114 | |
| 115 | /*ASFVOLT_LOG(ASFVOLT_DEBUG, "Onu's(%d) Serial number %02x%02x%02x%2x%02x%02x%02x%02x\n", |
| 116 | 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 | |
| 124 | ASFVOLT_LOG(ASFVOLT_DEBUG, |
| 125 | "\n ....SENT SUBSCRIBER TERMINAL %s UP %d on interface %d...\n", |
| 126 | (BCM_ERR_OK != err) ? "NOT" : "\b", |
| 127 | subs_terminal_key.sub_term_id, |
| 128 | subs_terminal_key.intf_id); |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | ASFVOLT_LOG(ASFVOLT_DEBUG, |
| 133 | "Skipping activation of subscriber terminal %d on interface %d\n", |
| 134 | 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 | ********************************************************************/ |
| 148 | bcmos_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 " |
| 164 | "on PON %d\n", |
| 165 | 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 " |
| 185 | "on PON %d\n", |
| 186 | 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 | { |
| 205 | ASFVOLT_LOG(ASFVOLT_ERROR, |
| 206 | "Invalid object type %d for subscriber terminal indication\n", |
| 207 | obj->obj_type); |
| 208 | |
| 209 | } |
| 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 | ********************************************************************/ |
| 219 | uint32_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 | |
| 225 | ASFVOLT_LOG(ASFVOLT_INFO, |
| 226 | "Processing subscriber terminal cfg clear: %d\n", |
| 227 | terminal_key->sub_term_id); |
| 228 | |
| 229 | if (terminal_key->has_sub_term_id && |
| 230 | terminal_key->has_intf_id) |
| 231 | { |
| 232 | key.sub_term_id = terminal_key->sub_term_id ; |
| 233 | key.intf_id = terminal_key->intf_id ; |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | ASFVOLT_LOG(ASFVOLT_ERROR, |
| 238 | "Invalid Key to handle subscriber terminal clear Req.subscriber_terminal_id(%d), Interface ID(%d)\n", |
| 239 | key.sub_term_id, key.intf_id); |
| 240 | |
| 241 | return BAL_ERRNO__BAL_ERR_PARM; |
| 242 | } |
| 243 | |
| 244 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr); |
| 245 | err = BAL_ERRNO__BAL_ERR_OK; |
| 246 | return err; |
| 247 | } |
| 248 | |
| 249 | /********************************************************************\ |
| 250 | * Function : bal_subscriber_terminal_cfg_get * |
| 251 | * Description : Get the subscriber terminal(ONU) configuration * |
| 252 | ********************************************************************/ |
| 253 | uint32_t bal_subscriber_terminal_cfg_get(BalSubscriberTerminalKey *terminal_key, |
| 254 | BalSubscriberTerminalCfg *onu_cfg) |
| 255 | { |
| 256 | |
| 257 | bcmos_errno err = BCM_ERR_OK; |
| 258 | bcmbal_subscriber_terminal_cfg cfg; /**< declare main API struct */ |
| 259 | bcmbal_subscriber_terminal_key key = { }; /**< declare key */ |
| 260 | uint8_t *list_mem; /**< declare memory buffer for variable-sized lists */ |
| 261 | |
| 262 | ASFVOLT_LOG(ASFVOLT_INFO, |
| 263 | "Processing subscriber terminal cfg get: %d\n", |
| 264 | onu_cfg->key->sub_term_id); |
| 265 | |
| 266 | if (terminal_key->has_sub_term_id && |
| 267 | terminal_key->has_intf_id) |
| 268 | { |
| 269 | key.sub_term_id = terminal_key->sub_term_id ; |
| 270 | key.intf_id = terminal_key->intf_id ; |
| 271 | } |
| 272 | else |
| 273 | { |
| 274 | ASFVOLT_LOG(ASFVOLT_ERROR, |
| 275 | "Invalid Key to handle subscriber terminal Cfg Get subscriber_terminal_id(%d), Interface ID(%d)\n", |
| 276 | key.sub_term_id, key.intf_id); |
| 277 | |
| 278 | return BAL_ERRNO__BAL_ERR_PARM; |
| 279 | } |
| 280 | |
| 281 | /* init the API struct */ |
| 282 | BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key); |
| 283 | |
| 284 | BCMBAL_CFG_PROP_GET(&cfg, subscriber_terminal, all_properties); |
| 285 | |
| 286 | /* set memory to use for variable-sized lists */ |
| 287 | list_mem = malloc(BAL_DYNAMIC_LIST_BUFFER_SIZE); |
| 288 | if (list_mem == NULL) |
| 289 | { |
| 290 | |
| 291 | ASFVOLT_LOG(ASFVOLT_ERROR, |
| 292 | "Memory allocation failed while handling subscriber terminal cfg get subscriber_terminal_id(%d), Interface ID(%d)\n", |
| 293 | key.sub_term_id, key.intf_id); |
| 294 | return BAL_ERRNO__BAL_ERR_NOMEM; |
| 295 | } |
| 296 | |
| 297 | memset(list_mem, 0, BAL_DYNAMIC_LIST_BUFFER_SIZE); |
| 298 | BCMBAL_CFG_LIST_BUF_SET(&cfg, subscriber_terminal, list_mem, BAL_DYNAMIC_LIST_BUFFER_SIZE); |
| 299 | |
| 300 | /* call API */ |
| 301 | err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &cfg.hdr); |
| 302 | if (err != BCM_ERR_OK) |
| 303 | { |
| 304 | ASFVOLT_LOG(ASFVOLT_ERROR, |
| 305 | "Failed to get information from BAL subscriber_terminal_id(%d), Interface ID(%d)\n", |
| 306 | key.sub_term_id, key.intf_id); |
| 307 | return BAL_ERRNO__BAL_ERR_INTERNAL; |
| 308 | } |
| 309 | |
| 310 | ASFVOLT_LOG(ASFVOLT_INFO, |
| 311 | "To-Do. Send subscriber terminal details to Adapter\n"); |
| 312 | return BAL_ERRNO__BAL_ERR_OK; |
| 313 | } |