1 /*
2  * Copyright (c) 2024 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 #ifndef WIFI_DIRECT_LINK_INFO_H
16 #define WIFI_DIRECT_LINK_INFO_H
17 
18 #include <any>
19 #include <map>
20 #include "ipv4_info.h"
21 #include "serializable.h"
22 #include "info_container.h"
23 #include "wifi_direct_types.h"
24 
25 namespace OHOS::SoftBus {
26 class NegotiateMessage;
27 enum class LinkInfoKey {
28     LOCAL_INTERFACE = 0,
29     REMOTE_INTERFACE = 1,
30     LOCAL_LINK_MODE = 2,
31     REMOTE_LINK_MODE = 3,
32     CENTER_20M = 4,
33     CENTER_FREQUENCY1 = 5,
34     CENTER_FREQUENCY2 = 6,
35     BANDWIDTH = 7,
36     SSID = 8,
37     BSSID = 9,
38     PSK = 10,
39     IS_DHCP = 11,
40     LOCAL_IPV4 = 12,
41     REMOTE_IPV4 = 13,
42     AUTH_PORT = 14,
43     MAX_PHYSICAL_RATE = 15,
44     REMOTE_DEVICE = 16,
45     STATUS = 17,
46     LOCAL_BASE_MAC = 18,
47     REMOTE_BASE_MAC = 19,
48     IS_CLIENT = 20,
49     LOCAL_IPV6 = 21,
50     REMOTE_IPV6 = 22,
51     CUSTOM_PORT = 23,
52     IPADDR_TYPE = 24,
53 };
54 
55 class LinkInfo : public Serializable, public InfoContainer<LinkInfoKey> {
56 public:
57     enum class LinkMode {
58         INVALID = -1,
59         NONE = 0,
60         STA = 1,
61         AP = 2,
62         GO = 4,
63         GC = 8,
64         HML = 16,
65     };
66 
67     LinkInfo() = default;
68     LinkInfo(const std::string &localInterface, const std::string &remoteInterface,
69              LinkMode localMode, LinkMode remoteMode);
70 
71     int Marshalling(WifiDirectProtocol &protocol, std::vector<uint8_t> &output) const override;
72     int Unmarshalling(WifiDirectProtocol &protocol, const std::vector<uint8_t> &input) override;
73 
74     void SetLocalInterface(const std::string &interface);
75     std::string GetLocalInterface() const;
76 
77     void SetRemoteInterface(const std::string &interface);
78     std::string GetRemoteInterface() const;
79 
80     void SetLocalLinkMode(LinkMode mode);
81     LinkMode GetLocalLinkMode() const;
82 
83     void SetRemoteLinkMode(LinkMode mode);
84     LinkMode GetRemoteLinkMode() const;
85 
86     void SetCenter20M(int freq);
87     int GetCenter20M() const;
88 
89     void SetCenterFrequency1(int freq);
90     int GetCenterFrequency1() const;
91 
92     void SetCenterFrequency2(int freq);
93     int GetCenterFrequency2() const;
94 
95     void SetBandWidth(int bandWidth);
96     int GetBandWidth() const;
97 
98     void SetSsid(const std::string &ssid);
99     std::string GetSsid() const;
100 
101     void SetBssid(const std::string &bssid);
102     std::string GetBssid() const;
103 
104     void SetPsk(const std::string &psk);
105     std::string GetPsk() const;
106 
107     void SetIsDhcp(bool isDhcp);
108     bool GetIsDhcp() const;
109 
110     void SetLocalIpv4Info(const Ipv4Info &ipv4Info);
111     Ipv4Info GetLocalIpv4Info() const;
112 
113     void SetRemoteIpv4Info(const Ipv4Info &ipv4Info);
114     Ipv4Info GetRemoteIpv4Info() const;
115 
116     void SetAuthPort(int port);
117     int GetAuthPort() const;
118 
119     void SetMaxPhysicalRate(int rate);
120     int GetMaxPhysicalRate() const;
121 
122     void SetRemoteDevice(const std::string &device);
123     std::string GetRemoteDevice() const;
124 
125     void SetStatus(int status);
126     int GetStatus() const;
127 
128     void SetLocalBaseMac(const std::string &mac);
129     std::string GetLocalBaseMac() const;
130 
131     void SetRemoteBaseMac(const std::string &mac);
132     std::string GetRemoteBaseMac() const;
133 
134     void SetIsClient(bool client);
135     bool GetIsClient() const;
136 
137     void SetLocalIpv6(const std::string &value);
138     std::string GetLocalIpv6() const;
139 
140     void SetRemoteIpv6(const std::string &value);
141     std::string GetRemoteIpv6() const;
142 
143     void SetCustomPort(int value);
144     int GetCustomPort();
145 
146     void SetIpAddrType(enum IpAddrType value);
147     enum IpAddrType GetIpAddrType();
148 };
149 }
150 #endif
151