• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "hal_sys_param.h"
17 
18 #define ETH_ALEN 6
19 #define MAC_BITS 4
20 #define HEX_A 0xa
21 #define MAC_HIGH_MASK 0xf0
22 #define MAC_LOW_MASK 0x0f
23 #define CHAR_NUM_OFFSET 0x30
24 #define CHAR_CAPITAL_OFFSET 0x37
25 #define STR_END_FLAG '\0'
26 
27 typedef unsigned char               u8;
28 
29 static char serialNumber[2*ETH_ALEN + 1];
30 
Hex2Char(u8 hex)31 static char Hex2Char(u8 hex)
32 {
33     if (hex < HEX_A) {
34         return hex + CHAR_NUM_OFFSET;
35     } else {
36         return hex + CHAR_CAPITAL_OFFSET;
37     }
38 }
39 
HalGetSerial(void)40 const char* HalGetSerial(void)
41 {
42     char macAddr[ETH_ALEN];
43     // as devboard has no production serial number, we just
44     // use wifi mac address as device serial number.
45     if (serialNumber[0] == STR_END_FLAG) {
46         extern int bwifi_get_own_mac(u8 *addr);
47         bwifi_get_own_mac(macAddr);
48         int j = 0;
49         for (int i = 0; i < ETH_ALEN; i++) {
50             u8 lowFour, highFour;
51             highFour = (macAddr[i] & MAC_HIGH_MASK) >> MAC_BITS;
52             serialNumber[j] = Hex2Char(highFour);
53             j++;
54             lowFour = macAddr[i] & MAC_LOW_MASK;
55             serialNumber[j] = Hex2Char(lowFour);
56             j++;
57         }
58     }
59     return serialNumber;
60 }
61 /**
62  * @brief implement for js kvstorekit/filekit
63  */
GetDataPath(void)64 const char *GetDataPath(void)
65 {
66     return "/data";
67 }
68 
RefreshAllServiceTimeStamp(void)69 void RefreshAllServiceTimeStamp(void)
70 {}
71