blob: 21ca84bd17b824cb081e69271d6c729e9a8ccc85 [file] [log] [blame]
Shad Ansari01b0e652018-04-05 21:02:53 +00001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Shad Ansari01b0e652018-04-05 21:02:53 +00003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * 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
Shad Ansari01b0e652018-04-05 21:02:53 +00007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Shad Ansari01b0e652018-04-05 21:02:53 +00009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * 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 */
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000016#include <string.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000017#include "utils.h"
18
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000019std::string serial_number_to_str(bcmolt_serial_number* serial_number) {
Shad Ansari01b0e652018-04-05 21:02:53 +000020#define SERIAL_NUMBER_SIZE 12
Craig Lutgen88a22ad2018-10-04 12:30:46 -050021 char buff[SERIAL_NUMBER_SIZE+1];
Shad Ansari01b0e652018-04-05 21:02:53 +000022
23 sprintf(buff, "%c%c%c%c%1X%1X%1X%1X%1X%1X%1X%1X",
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000024 serial_number->vendor_id.arr[0],
25 serial_number->vendor_id.arr[1],
26 serial_number->vendor_id.arr[2],
27 serial_number->vendor_id.arr[3],
28 serial_number->vendor_specific.arr[0]>>4 & 0x0f,
29 serial_number->vendor_specific.arr[0] & 0x0f,
30 serial_number->vendor_specific.arr[1]>>4 & 0x0f,
31 serial_number->vendor_specific.arr[1] & 0x0f,
32 serial_number->vendor_specific.arr[2]>>4 & 0x0f,
33 serial_number->vendor_specific.arr[2] & 0x0f,
34 serial_number->vendor_specific.arr[3]>>4 & 0x0f,
35 serial_number->vendor_specific.arr[3] & 0x0f);
Shad Ansari01b0e652018-04-05 21:02:53 +000036
37 return buff;
38}
Craig Lutgen88a22ad2018-10-04 12:30:46 -050039
40std::string vendor_specific_to_str(char const * const vendor_specific) {
41 char buff[SERIAL_NUMBER_SIZE+1];
42
43 sprintf(buff, "%1X%1X%1X%1X%1X%1X%1X%1X",
44 vendor_specific[0]>>4 & 0x0f,
45 vendor_specific[0] & 0x0f,
46 vendor_specific[1]>>4 & 0x0f,
47 vendor_specific[1] & 0x0f,
48 vendor_specific[2]>>4 & 0x0f,
49 vendor_specific[2] & 0x0f,
50 vendor_specific[3]>>4 & 0x0f,
51 vendor_specific[3] & 0x0f);
52
53 return buff;
54}
55