• 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 <queue>
17 #include <mutex>
18 #include "dhcp_define.h"
19 #include "dhcp_message.h"
20 
21 #ifndef OHOS_DHCP_MESSAGE_SIM_H
22 #define OHOS_DHCP_MESSAGE_SIM_H
23 
24 typedef struct DhcpClientConfig DhcpClientConfig;
25 
26 typedef struct DhcpClientContext DhcpClientContext;
27 
28 
29 namespace OHOS {
30 namespace Wifi {
31 class DhcpMsgManager
32 {
33 public:
34     static DhcpMsgManager &GetInstance(void);
35 
36     int SendTotal();
37 
38     int RecvTotal();
39 
40     int PushSendMsg(const DhcpMessage &msg);
41     int PushRecvMsg(const DhcpMessage &msg);
42 
43     void PopSendMsg();
44 
45     bool FrontSendMsg(DhcpMessage *msg);
46     void PopRecvMsg();
47 
48     void SetClientIp(uint32_t ipAddr);
49     uint32_t GetClientIp() const;
50 private:
DhcpMsgManager()51     DhcpMsgManager(){};
~DhcpMsgManager()52     ~DhcpMsgManager(){};
53 
54     std::mutex m_recvQueueLocker;
55     std::queue<DhcpMessage> m_recvMessages;
56     std::mutex m_sendQueueLocker;
57     std::queue<DhcpMessage> m_sendMessages;
58     uint32_t m_clientIpAddress = 0;
59 };
60 }  // namespace Wifi
61 }  // namespace OHOS
62 
63 typedef struct {
64     int (*OnReceivedOffer)(DhcpMessage *msg);
65     int (*OnReceivedNak)( DhcpMessage *msg);
66     int (*OnReceivedAck)(DhcpMessage *msg);
67 } DhcpClientCallback;
68 
69 struct DhcpClientConfig
70 {
71     char ifname[IFACE_NAME_SIZE];
72     uint8_t chaddr[DHCP_HWADDR_LENGTH];
73 };
74 
75 DhcpClientContext *InitialDhcpClient(DhcpClientConfig *config);
76 
77 int *StatrDhcpClient(DhcpClientContext *config);
78 
79 int SendDhcpMessage(DhcpClientContext *ctx, PDhcpMsgInfo msg);
80 
81 int DhcpDiscover(DhcpClientContext *ctx);
82 
83 int DhcpRequest(DhcpClientContext *ctx);
84 
85 int DhcpInform(DhcpClientContext *ctx);
86 
87 int DhcpDecline(DhcpClientContext *ctx);
88 
89 int DhcpRelease(DhcpClientContext *ctx);
90 
91 int StopDhcpClient(DhcpClientContext *ctx);
92 
93 int GetDhcpClinetState(DhcpClientContext *ctx);
94 
95 int FreeDhcpClient(DhcpClientContext *ctx);
96 int InitMessage(DhcpClientContext *ctx, PDhcpMsgInfo msg, uint8_t msgType);
97 int FillHwAddr(uint8_t *dst, size_t dsize, uint8_t *src, size_t ssize);
98 int ParseDhcpOptions(PDhcpMsgInfo msg);
99 int ParseReceivedOptions(PDhcpMsgInfo msg);
100 
101 #endif