• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
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 "nstackx_dev.h"
17 #include "nstackx_util.h"
18 #include "nstackx_error.h"
19 #include "nstackx_log.h"
20 #include "securec.h"
21 
22 #define TAG "nStackXDev"
23 
24 int32_t GetConnectionTypeByDev(const uint32_t sourceIp, uint16_t *connectType);
25 
GetConnectionTypeByIP(const uint32_t sourceIp,const uint32_t destinationIp,uint16_t * connectType)26 static int32_t GetConnectionTypeByIP(const uint32_t sourceIp, const uint32_t destinationIp, uint16_t *connectType)
27 {
28     if (sourceIp == htonl(SOFTAP_ADDR_KEY) || destinationIp == htonl(SOFTAP_ADDR_KEY) ||
29         sourceIp == htonl(P2P_ADDR_KEY) || destinationIp == htonl(P2P_ADDR_KEY)) {
30         *connectType = CONNECT_TYPE_P2P;
31         LOGI(TAG, "connType is P2P(%u)", *connectType);
32         return NSTACKX_EOK;
33     }
34     return NSTACKX_EFAILED;
35 }
36 
GetConnectionType(const uint32_t sourceIp,const uint32_t destinationIp,uint16_t * connectType)37 int32_t GetConnectionType(const uint32_t sourceIp, const uint32_t destinationIp, uint16_t *connectType)
38 {
39     if (GetConnectionTypeByIP(sourceIp, destinationIp, connectType) == NSTACKX_EOK) {
40         return NSTACKX_EOK;
41     }
42     return GetConnectionTypeByDev(sourceIp, connectType);
43 }
44 
DFileGetDeviceBits(void)45 uint8_t DFileGetDeviceBits(void)
46 {
47     if (TYPE_BITS_NUM(char *) == DEVICE_32_BITS) {
48         return DEVICE_32_BITS;
49     }
50 
51     return DEVICE_64_BITS;
52 }