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 #define P2P_DEV_NAME_PRE "p2p" 38 #define WLAN_DEV_NAME_PRE "wlan" 39 #define ETH_DEV_NAME_PRE "eth" 40 #define USB_DEV_NAME_PRE "rndis" 41 #define WIFI_DIRECT_NAME "Wi-Fi Direct" 42 #define INTERFCAE_NAME_MAX_LENGTH (128 + 4) 43 #define INTERFACE_GUID_MAX_LENGTH (256 + 4) 44 #define INTERFACE_NETMASK (0xffffff) 45 #define INTERFCAE_DES_MAX_LENGTH 128 46 #define INTERFCAE_ADDR_MAX_LENGTH 16 47 #define INTERFCAE_TYPE_MAX_LENGTH 20 48 #define INTERFACE_MAX 16 49 #define SOFTAP_ADDR_KEY (0xc0a82b01) 50 #define P2P_ADDR_KEY (0xc0a83101) 51 52 NSTACKX_EXPORT int32_t BindToDevice(SocketDesc sockfd, const struct sockaddr_in *localAddr); 53 NSTACKX_EXPORT int32_t GetIfBroadcastIp(const char *ifName, char *ipString, size_t ipStringLen); 54 NSTACKX_EXPORT int32_t GetConnectionType(const uint32_t sourceIp, const uint32_t destinationIp, uint16_t *connectType); 55 NSTACKX_EXPORT int32_t BindToTargetDev(SocketDesc sockfd, const char *targetInterfaceName); 56 NSTACKX_EXPORT int32_t GetInterfaceNameByIP(uint32_t sourceIp, char *interfaceName, size_t nameLen); 57 NSTACKX_EXPORT void BindToDevInTheSameLan(SocketDesc sockfd, const struct sockaddr_in *sockAddr); 58 59 #endif // NSTACKX_DEV_H 60