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 #ifndef NSTACKX_DEV_H 17 #define NSTACKX_DEV_H 18 19 #include "nstackx_common_header.h" 20 21 #ifndef UNUSED 22 #ifdef __GNUC__ 23 #define UNUSED __attribute__((unused)) 24 #else /* not a GCC */ 25 #define UNUSED 26 #endif /* GCC */ 27 #endif 28 29 /* DFile connect type list. */ 30 typedef enum { 31 CONNECT_TYPE_NONE = 0, 32 CONNECT_TYPE_P2P, 33 CONNECT_TYPE_WLAN, 34 CONNECT_TYPE_MAX, 35 } ConnectType; 36 37 typedef enum { 38 DEVICE_32_BITS = 32, 39 DEVICE_64_BITS = 64, 40 } DeviceType; 41 42 #define P2P_DEV_NAME_PRE "p2p" 43 #define WLAN_DEV_NAME_PRE "wlan" 44 #ifndef ETH_DEV_NAME_PRE 45 #define ETH_DEV_NAME_PRE "eth" 46 #endif 47 #define USB_DEV_NAME_PRE "rndis" 48 #define WIFI_DIRECT_NAME "Wi-Fi Direct" 49 #define INTERFCAE_NAME_MAX_LENGTH (128 + 4) 50 #define INTERFACE_GUID_MAX_LENGTH (256 + 4) 51 #define INTERFACE_NETMASK (0xffffff) 52 #define INTERFCAE_DES_MAX_LENGTH 128 53 #define INTERFCAE_ADDR_MAX_LENGTH 16 54 #define INTERFCAE_TYPE_MAX_LENGTH 20 55 #define INTERFACE_MAX 16 56 #define SOFTAP_ADDR_KEY (0xc0a82b01) 57 #define P2P_ADDR_KEY (0xc0a83101) 58 59 NSTACKX_EXPORT int32_t BindToDevice(SocketDesc sockfd, const struct sockaddr_in *localAddr); 60 NSTACKX_EXPORT int32_t GetIfBroadcastIp(const char *ifName, char *ipString, size_t ipStringLen); 61 NSTACKX_EXPORT int32_t GetConnectionType(const uint32_t sourceIp, const uint32_t destinationIp, uint16_t *connectType); 62 NSTACKX_EXPORT int32_t BindToTargetDev(SocketDesc sockfd, const char *targetInterfaceName); 63 NSTACKX_EXPORT int32_t GetInterfaceNameByIP(uint32_t sourceIp, char *interfaceName, size_t nameLen); 64 NSTACKX_EXPORT void BindToDevInTheSameLan(SocketDesc sockfd, const struct sockaddr_in *sockAddr); 65 NSTACKX_EXPORT uint8_t DFileGetDeviceBits(void); 66 67 #endif // NSTACKX_DEV_H 68