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 | /* 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" |
| 33 | |
| 34 | /********************************************************************\ |
| 35 | * Function : bal_access_terminal_cfg_req * |
| 36 | * Description : Configures the PON and NNI interfaces * |
| 37 | * of OLT Device * |
| 38 | ********************************************************************/ |
| 39 | uint32_t bal_packet_cfg_req(BalPacketCfg *packet) |
| 40 | { |
| 41 | bcmos_errno err = BCM_ERR_OK; |
| 42 | switch(packet->key->packet_send_dest->type) |
| 43 | { |
| 44 | case BAL_DEST_TYPE__BAL_DEST_TYPE_NNI: |
| 45 | { |
| 46 | ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Send packet msg to NNI not yet implemented\n"); |
| 47 | } |
| 48 | break; |
| 49 | case BAL_DEST_TYPE__BAL_DEST_TYPE_SUB_TERM: |
| 50 | { |
| 51 | ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Send packet msg to ONU not yet implemented\n"); |
| 52 | } |
| 53 | break; |
| 54 | case BAL_DEST_TYPE__BAL_DEST_TYPE_SVC_PORT: |
| 55 | { |
| 56 | ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Send packet msg to PON not yet implemented\n"); |
| 57 | } |
| 58 | break; |
| 59 | case BAL_DEST_TYPE__BAL_DEST_TYPE_ITU_OMCI_CHANNEL: |
| 60 | { |
| 61 | bcmbal_access_term_id aterm_id = 0; /* Assume a single access_terminal instance */ |
| 62 | bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */ |
| 63 | /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */ |
| 64 | bcmbal_dest proxy_pkt_dest = { .type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL, |
| 65 | .u.itu_omci_channel.sub_term_id = packet->key->packet_send_dest->itu_omci_channel->sub_term_id, |
| 66 | .u.itu_omci_channel.intf_id = packet->key->packet_send_dest->itu_omci_channel->intf_id }; |
| 67 | 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 */ |
| 68 | /* Send the OMCI packet using the BAL remote proxy API */ |
| 69 | uint16_t idx1 = 0; |
| 70 | uint16_t idx2 = 0; |
| 71 | uint8_t arraySend[buf.len]; |
| 72 | char str1[MAX_CHAR_LENGTH]; |
| 73 | char str2[MAX_CHAR_LENGTH]; |
| 74 | memset(&arraySend,0,buf.len); |
| 75 | ASFVOLT_LOG(ASFVOLT_DEBUG,"\nSending omci msg to ONU of length is %d\n",buf.len); |
| 76 | for(idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) |
| 77 | { |
| 78 | sprintf(str1,"%c",packet->data->pkt.data[idx1]); |
| 79 | sprintf(str2,"%c",packet->data->pkt.data[++idx1]); |
| 80 | strcat(str1,str2); |
| 81 | arraySend[idx2] = strtol(str1, NULL, 16); |
| 82 | } |
| 83 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 84 | memcpy(buf.val,(uint8_t *)arraySend,buf.len); |
| 85 | ASFVOLT_LOG(ASFVOLT_DEBUG,"\nAfter converting it into hex\n"); |
| 86 | for(idx2=0; idx2<buf.len; idx2++) |
| 87 | { |
| 88 | printf("%02x", buf.val[idx2]); |
| 89 | } |
| 90 | printf("\n"); |
| 91 | err = bcmbal_pkt_send(aterm_id, |
| 92 | proxy_pkt_dest, |
| 93 | (const char *)(buf.val), |
| 94 | buf.len); |
| 95 | ASFVOLT_LOG(ASFVOLT_DEBUG, "\n OMCI request msg of length(%d) sent to ONU(%d) through PON(%d)\n", |
| 96 | buf.len, |
| 97 | packet->key->packet_send_dest->itu_omci_channel->sub_term_id, |
| 98 | packet->key->packet_send_dest->itu_omci_channel->intf_id); |
| 99 | bcmos_free(buf.val); |
| 100 | } |
| 101 | break; |
| 102 | case BAL_DEST_TYPE__BAL_DEST_TYPE_IEEE_OAM_CHANNEL: |
| 103 | { |
| 104 | ASFVOLT_LOG(ASFVOLT_DEBUG, "\n PLOAM msg not yet implemented\n"); |
| 105 | } |
| 106 | break; |
| 107 | default: |
| 108 | { |
| 109 | ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Invalid dest type\n"); |
| 110 | } |
| 111 | break; |
| 112 | } |
| 113 | if (BCM_ERR_OK != err) |
| 114 | { |
| 115 | /* recover from any error encountered while sending */ |
| 116 | } |
| 117 | return err; |
| 118 | } |