1518678f8Sopenharmony_ci/* 2518678f8Sopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3518678f8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4518678f8Sopenharmony_ci * you may not use this file except in compliance with the License. 5518678f8Sopenharmony_ci * You may obtain a copy of the License at 6518678f8Sopenharmony_ci * 7518678f8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8518678f8Sopenharmony_ci * 9518678f8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10518678f8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11518678f8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12518678f8Sopenharmony_ci * See the License for the specific language governing permissions and 13518678f8Sopenharmony_ci * limitations under the License. 14518678f8Sopenharmony_ci */ 15518678f8Sopenharmony_ci 16518678f8Sopenharmony_ci#ifndef OHOS_DHCP_BINDING_H 17518678f8Sopenharmony_ci#define OHOS_DHCP_BINDING_H 18518678f8Sopenharmony_ci 19518678f8Sopenharmony_ci#include <stdint.h> 20518678f8Sopenharmony_ci 21518678f8Sopenharmony_ci#ifdef __cplusplus 22518678f8Sopenharmony_ciextern "C" { 23518678f8Sopenharmony_ci#endif 24518678f8Sopenharmony_ci 25518678f8Sopenharmony_ci#define DEVICE_NAME_STRING_LENGTH 64 26518678f8Sopenharmony_cienum BindingMode { BIND_MODE_STATIC = 0, BIND_MODE_DYNAMIC, BIND_MODE_RESERVED }; 27518678f8Sopenharmony_ci 28518678f8Sopenharmony_cienum BindingState { BIND_NONE = 0, BIND_PENDING, BIND_ASSOCIATED, BIND_EXPIRED, BIND_RELEASED }; 29518678f8Sopenharmony_ci 30518678f8Sopenharmony_citypedef struct AddressBinding AddressBinding; 31518678f8Sopenharmony_cistruct AddressBinding { 32518678f8Sopenharmony_ci uint32_t ipAddress; 33518678f8Sopenharmony_ci uint8_t chaddr[16]; 34518678f8Sopenharmony_ci uint32_t clientId; 35518678f8Sopenharmony_ci uint64_t bindingTime; 36518678f8Sopenharmony_ci uint64_t pendingTime; 37518678f8Sopenharmony_ci uint64_t expireIn; 38518678f8Sopenharmony_ci uint64_t leaseTime; 39518678f8Sopenharmony_ci uint64_t pendingInterval; 40518678f8Sopenharmony_ci int bindingStatus; 41518678f8Sopenharmony_ci int bindingMode; 42518678f8Sopenharmony_ci char deviceName[DEVICE_NAME_STRING_LENGTH]; 43518678f8Sopenharmony_ci char userClass[DEVICE_NAME_STRING_LENGTH]; // User-Class 44518678f8Sopenharmony_ci char portalUrl[DEVICE_NAME_STRING_LENGTH]; // portalurl 45518678f8Sopenharmony_ci bool rapidCommit; // Rapid Commit 46518678f8Sopenharmony_ci int ipv6Only; // IPv6-Only Preferred 47518678f8Sopenharmony_ci}; 48518678f8Sopenharmony_citypedef struct AddressBinding *PAddressBinding; 49518678f8Sopenharmony_ci 50518678f8Sopenharmony_citypedef struct AddressBindingNode AddressBindingNode; 51518678f8Sopenharmony_cistruct AddressBindingNode { 52518678f8Sopenharmony_ci AddressBinding bind; 53518678f8Sopenharmony_ci AddressBindingNode *next; 54518678f8Sopenharmony_ci}; 55518678f8Sopenharmony_citypedef struct AddressBindingNode *PAddressBindingNode; 56518678f8Sopenharmony_ci 57518678f8Sopenharmony_citypedef struct AddressBindingList AddressBindingList; 58518678f8Sopenharmony_cistruct AddressBindingList { 59518678f8Sopenharmony_ci int size; 60518678f8Sopenharmony_ci AddressBindingNode *first; 61518678f8Sopenharmony_ci}; 62518678f8Sopenharmony_citypedef struct AddressBindingList *PAddressBindingList; 63518678f8Sopenharmony_ci 64518678f8Sopenharmony_ciuint64_t NextPendingInterval(uint64_t pendingInterval); 65518678f8Sopenharmony_ciint IsExpire(AddressBinding *binding); 66518678f8Sopenharmony_ciint WriteAddressBinding(const AddressBinding *binding, char *out, uint32_t size); 67518678f8Sopenharmony_ciint ParseAddressBinding(AddressBinding *binding, const char *buf); 68518678f8Sopenharmony_ci 69518678f8Sopenharmony_ci#ifdef __cplusplus 70518678f8Sopenharmony_ci} 71518678f8Sopenharmony_ci#endif 72518678f8Sopenharmony_ci#endif 73