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