1 /*
2  * Copyright (C) 2021-2022 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 OHOS_DHCP_BINDING_H
17 #define OHOS_DHCP_BINDING_H
18 
19 #include <stdint.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define DEVICE_NAME_STRING_LENGTH 64
26 enum BindingMode { BIND_MODE_STATIC = 0, BIND_MODE_DYNAMIC, BIND_MODE_RESERVED };
27 
28 enum BindingState { BIND_NONE = 0, BIND_PENDING, BIND_ASSOCIATED, BIND_EXPIRED, BIND_RELEASED };
29 
30 typedef struct AddressBinding AddressBinding;
31 struct AddressBinding {
32     uint32_t ipAddress;
33     uint8_t chaddr[16];
34     uint32_t clientId;
35     uint64_t bindingTime;
36     uint64_t pendingTime;
37     uint64_t expireIn;
38     uint64_t leaseTime;
39     uint64_t pendingInterval;
40     int bindingStatus;
41     int bindingMode;
42     char deviceName[DEVICE_NAME_STRING_LENGTH];
43     char userClass[DEVICE_NAME_STRING_LENGTH]; // User-Class
44     char portalUrl[DEVICE_NAME_STRING_LENGTH]; // portalurl
45     bool rapidCommit; // Rapid Commit
46     int ipv6Only; // IPv6-Only Preferred
47 };
48 typedef struct AddressBinding *PAddressBinding;
49 
50 typedef struct AddressBindingNode AddressBindingNode;
51 struct AddressBindingNode {
52     AddressBinding bind;
53     AddressBindingNode *next;
54 };
55 typedef struct AddressBindingNode *PAddressBindingNode;
56 
57 typedef struct AddressBindingList AddressBindingList;
58 struct AddressBindingList {
59     int size;
60     AddressBindingNode *first;
61 };
62 typedef struct AddressBindingList *PAddressBindingList;
63 
64 uint64_t NextPendingInterval(uint64_t pendingInterval);
65 int IsExpire(AddressBinding *binding);
66 int WriteAddressBinding(const AddressBinding *binding, char *out, uint32_t size);
67 int ParseAddressBinding(AddressBinding *binding, const char *buf);
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 #endif
73