• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_INFO_CONTAINER_H
16 #define WIFI_DIRECT_INFO_CONTAINER_H
17 
18 #include <stdbool.h>
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include "softbus_adapter_mem.h"
23 #include "wifi_direct_defines.h"
24 #include "wifi_direct_types.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 enum InfoContainerEntryType {
31     STRING = 1,
32     STRING_ARRAY = 2,
33     INT = 3,
34     INT_ARRAY = 4,
35     BYTE = 5,
36     BYTE_ARRAY = 6,
37     BOOLEAN = 7,
38     INTERFACE_INFO_ARRAY = 8,
39     LONG = 9,
40     LINK_INFO = 10,
41     IPV4_INFO = 11,
42     IPV4_INFO_ARRAY = 12,
43     AUTH_CONNECTION = 13,
44     EXTRA_DATA_ARRAY = 14,
45     INNER_LINK = 15,
46     COEXIST_SET = 16,
47 };
48 
49 #define CONTAINER_FLAG (1 << 0)
50 #define CONTAINER_ARRAY_FLAG (1 << 1)
51 #define MAC_ADDR_FLAG (1 << 2)
52 #define IP_ADDR_FLAG (1 << 2)
53 #define DEVICE_ID_FLAG (1 << 3)
54 #define DUMP_FLAG (1 << 4)
55 
56 struct InfoContainerKeyProperty {
57     uint32_t tag;
58     char *content;
59     enum InfoContainerEntryType type;
60     uint32_t flag;
61 };
62 
63 struct WifiDirectProtocol;
64 
65 #define IC_KEY_PROPERTY(key, tag, content, type, flag)                                              \
66     [key] = { tag, content, type, flag }
67 
68 #define IC_DECLARE_KEY_PROPERTIES(type, max)                                                        \
69 static struct InfoContainerKeyProperty type##KeyProperties[max]
70 
71 #define INFO_CONTAINER_BASE(type, max)                                                              \
72     void (*deepCopy)(struct type *self, struct type *other);                                        \
73     void (*putInt)(struct type *self, size_t key, int32_t value);                                   \
74     void (*putBoolean)(struct type *self, size_t key, bool value);                                  \
75     void (*putPointer)(struct type *self, size_t key, void **ptr);                                  \
76     void (*putString)(struct type *self, size_t key, const char *value);                            \
77     void (*putIntArray)(struct type *self, size_t key, int32_t *array, size_t arraySize);           \
78     void (*putRawData)(struct type *self, size_t key, void *value, size_t size);                    \
79     void (*putContainer)(struct type *self, size_t key, struct InfoContainer *container,            \
80                             size_t size);                                                           \
81     void (*putContainerArray)(struct type *self, size_t key, struct InfoContainer *containerArray,  \
82                               size_t containerArraySize, size_t containerSize);                     \
83                                                                                                     \
84     void* (*get)(struct type *self, size_t key, size_t *size, size_t *count);                       \
85     int32_t (*getInt)(struct type *self, size_t key, int32_t defaultValue);                         \
86     bool (*getBoolean)(struct type *self, size_t key, bool defaultValue);                           \
87     void* (*getPointer)(struct type *self, size_t key, void *defaultValue);                         \
88     char* (*getString)(struct type *self, size_t key, const char *defaultValue);                    \
89     void* (*getContainer)(struct type *self, size_t key);                                           \
90     void* (*getContainerArray)(struct type *self, size_t key, size_t *containerArraySize);          \
91     void* (*getRawData)(struct type *self, size_t key, size_t *size, void *defaultValue);           \
92                                                                                                     \
93     /* debug */                                                                                     \
94     void (*dump)(struct type *self);                                                                \
95                                                                                                     \
96     void (*remove)(struct type *self, size_t key);                                                  \
97     struct InfoContainerKeyProperty* (*getKeyProperty)(struct type *self, uint32_t key);            \
98                                                                                                     \
99     /* virtual method */                                                                            \
100     size_t (*getKeySize)(void);                                                                     \
101     const char* (*getContainerName)(void );                                                         \
102     bool (*marshalling)(struct type *self, struct WifiDirectProtocol *protocol);                    \
103     bool (*unmarshalling)(struct type *self, struct WifiDirectProtocol *protocol);                  \
104     void (*destructor)(struct type *self);                                                          \
105                                                                                                     \
106     /* data member */                                                                               \
107     struct InfoContainerKeyProperty *keyProperties;                                                 \
108     struct {                                                                                        \
109         void *data;                                                                                 \
110         size_t count;                                                                               \
111         size_t size;                                                                                \
112         bool remove;                                                                                \
113     } entries[max]
114 
115 struct InfoContainer {
116     INFO_CONTAINER_BASE(InfoContainer, 0);
117 };
118 
119 void InfoContainerConstructor(struct InfoContainer *self, struct InfoContainerKeyProperty *keyProperties, size_t max);
120 void InfoContainerDestructor(struct InfoContainer *self, size_t max);
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 #endif