RDK-B
vlan_hal.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's LICENSE file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21 * @file vlan_hal.h
22 * @author zhicheng_qiu@cable.comcast.com
23 * @brief For CCSP Component: VLAN_Provisioning_and_management
24 *
25 * @description This file gives the function prototypes used for the RDK-Broadband
26 * VLAN abstraction layer
27 */
28 
29 /**********************************************************************
30 
31  module: vlan_hal.h
32 
33  For CCSP Component: VLAN_Provisioning_and_management
34 
35  ---------------------------------------------------------------
36 
37  description:
38 
39  This header file gives the function call prototypes and
40  structure definitions used for the RDK-Broadband
41  VLAN abstraction layer
42 
43  ---------------------------------------------------------------
44 
45  environment:
46 
47  This HAL layer is intended to support VLAN drivers
48  through the System Calls.
49 
50  ---------------------------------------------------------------
51 
52  author:
53 
54  zhicheng_qiu@cable.comcast.com
55 
56 **********************************************************************/
57 
58 #ifndef __VLAN_HAL_H__
59 #define __VLAN_HAL_H__
60 
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include <string.h>
64 
65 #ifndef ULONG
66 #define ULONG unsigned long
67 #endif
68 
69 #ifndef BOOL
70 #define BOOL unsigned char
71 #endif
72 
73 #ifndef CHAR
74 #define CHAR char
75 #endif
76 
77 #ifndef UCHAR
78 #define UCHAR unsigned char
79 #endif
80 
81 #ifndef INT
82 #define INT int
83 #endif
84 
85 #ifndef UINT
86 #define UINT unsigned int
87 #endif
88 
89 #ifndef TRUE
90 #define TRUE 1
91 #endif
92 
93 #ifndef FALSE
94 #define FALSE 0
95 #endif
96 
97 #ifndef ENABLE
98 #define ENABLE 1
99 #endif
100 
101 #ifndef RETURN_OK
102 #define RETURN_OK 0
103 #endif
104 
105 #ifndef RETURN_ERR
106 #define RETURN_ERR -1
107 #endif
108 
109 /**
110  * @defgroup VLAN_HAL Virtual LAN HAL
111  *
112  * VLAN HAL layer is intended to support VLAN drivers through the System Calls.
113  *
114  * @defgroup VLAN_HAL_TYPES VLAN HAL Data Types
115  * @ingroup VLAN_HAL
116  *
117  * @defgroup VLAN_HAL_APIS VLAN HAL APIs
118  * @ingroup VLAN_HAL
119  *
120  **/
121 
122 /**
123  * @addtogroup VLAN_HAL_TYPES
124  * @{
125  */
126 
127 //defines for HAL version 1.0
128 #define VLAN_HAL_MAJOR_VERSION 1 /**< This is the major verion of this HAL. */
129 #define VLAN_HAL_MINOR_VERSION 0 /**< This is the minor verson of the HAL. */
130 #define VLAN_HAL_MAINTENANCE_VERSION 1 /**< This is the maintenance version of the HAL. */
131 
132 //defines for charecter length for VLAN configurartion
133 #define VLAN_HAL_MAX_VLANGROUP_TEXT_LENGTH 32
134 #define VLAN_HAL_MAX_VLANID_TEXT_LENGTH 32
135 #define VLAN_HAL_MAX_INTERFACE_NAME_TEXT_LENGTH 32
136 
137 #define VLAN_HAL_MAX_LINE_BUFFER_LENGTH 120
138 
139 /**********************************************************************
140  ENUMERATION DEFINITIONS
141 **********************************************************************/
142 
143 /**********************************************************************
144  STRUCTURE DEFINITIONS
145 **********************************************************************/
146 
147 // Structure for VLANID Maintainance
149 {
153 
155 
156 /** @} */ //END OF GROUP VLAN_HAL_TYPES
157 
158 /**********************************************************************
159  *
160  * VLAN HAL function prototypes
161  *
162 ***********************************************************************/
163 
164 /**
165  * @addtogroup VLAN_HAL_APIS
166  * @{
167  */
168 
169 /**
170 * @description This HAL is used to creat an new vlan group, and assig default vlanID.
171 * @param const char *groupName - bridge name
172 * @param const char *default_vlanID - default VLANID
173 *
174 * @return The status of the operation.
175 * @retval RETURN_OK if successful (or) return RETURN_OK If group is already exist and has expected vlanID
176 * @retval RETURN_ERR if any error is detected
177 *
178 * @execution Synchronous.
179 * @sideeffect None.
180 *
181 */
182 int vlan_hal_addGroup(const char *groupName, const char *default_vlanID);
183 
184 /**
185 * @description This HAL is used to delete existing vlan group, and delete correspond interface association.
186 * @param const char *groupName - bridge name
187 *
188 * @return The status of the operation.
189 * @retval RETURN_OK if successful (or) RETURN_OK If group is not exist
190 * @retval RETURN_ERR if any error is detected
191 *
192 * @execution Synchronous.
193 * @sideeffect None.
194 *
195 */
196 int vlan_hal_delGroup(const char *groupName);
197 
198 /**
199 * @description This HAL is used to add interface to existing vlan group, and assign the vlanID.
200 * @param const char *groupName - bridge name
201 * @param const char *ifName - interface name
202 * @param const char *vlanID - VLANID
203 *
204 * @return The status of the operation.
205 * @retval RETURN_OK if successful (or) RETURN_OK If interface is already in group, and has expected vlan ID
206 * @retval RETURN_ERR if group is not exist (or) if any error is detected
207 *
208 * @execution Synchronous.
209 * @sideeffect None.
210 *
211 */
212 int vlan_hal_addInterface(const char *groupName, const char *ifName, const char *vlanID);
213 
214 /**
215 * @description This HAL is used to deassociate existing interface from group.
216 * @param const char *groupName - bridge name
217 * @param const char *ifName - interface name
218 * @param const char *vlanID - VLANID
219 *
220 * @return The status of the operation.
221 * @retval RETURN_OK if successful (or) RETURN_OK If interface is not exist
222 * @retval RETURN_ERR if any error is detected
223 *
224 * @execution Synchronous.
225 * @sideeffect None.
226 *
227 */
228 int vlan_hal_delInterface(const char *groupName, const char *ifName, const char *vlanID);
229 
230 /**
231 * @description This HAL is used to dump the particular group setting, for debug purpose
232 * @param const char *groupName - bridge name
233 *
234 * @return The status of the operation.
235 * @retval RETURN_OK if successful
236 * @retval RETURN_ERR if any error is detected
237 *
238 * @execution Synchronous.
239 * @sideeffect None.
240 *
241 */
242 int vlan_hal_printGroup(const char *groupName);
243 
244 
245 /**
246 * @description This HAL is used dump all group setting, for debug purpose
247 * @param None.
248 *
249 * @return The status of the operation.
250 * @retval RETURN_OK if successful
251 * @retval RETURN_ERR if any error is detected
252 *
253 * @execution Synchronous.
254 * @sideeffect None.
255 *
256 */
258 
259 /**
260 * @description This HAL is used to deassociate all existing interface from group.
261 * @param const char *groupName - bridge name
262 *
263 * @return The status of the operation.
264 * @retval RETURN_OK if successful
265 * @retval RETURN_ERR if any error is detected
266 *
267 * @execution Synchronous.
268 * @sideeffect None.
269 *
270 */
271 
273 
274 /**
275 * @description This HAL utility is used identify given bridge available in linux bridge.
276 * @param const char * br_name - bridge name
277 *
278 * @return The status of the operation.
279 * @retval RETURN_OK if successful
280 * @retval RETURN_ERR if any error is detected
281 *
282 * @execution Synchronous.
283 * @sideeffect None.
284 *
285 */
286 
287 int _is_this_group_available_in_linux_bridge(char * br_name);
288 
289 /**
290 * @description This HAL utility is used identify given interface available in given bridge.
291 * @param const char * br_name - bridge name
292 * @param char *vlanID - VLAND ID
293 *
294 * @return The status of the operation.
295 * @retval RETURN_OK if successful
296 * @retval RETURN_ERR if any error is detected
297 *
298 * @execution Synchronous.
299 * @sideeffect None.
300 *
301 */
302 
303 int _is_this_interface_available_in_linux_bridge(char * if_name, char *vlanID);
304 
305 /**
306 * @description This HAL utility is used identify given interface available in anyone of linux bridge.
307 * @param char * if_name - interface name
308 * @param const char * br_name - bridge name
309 * @param char *vlanID - VLAND ID
310 *
311 * @return The status of the operation.
312 * @retval RETURN_OK if successful
313 * @retval RETURN_ERR if any error is detected
314 *
315 * @execution Synchronous.
316 * @sideeffect None.
317 *
318 */
319 
320 int _is_this_interface_available_in_given_linux_bridge(char * if_name, char * br_name,char *vlanID);
321 
322 /**
323 * @description This HAL utility is used get the buffer from shell output
324 * @param char * cmd - linux shell command
325 * @param char * out - construct the linux system command and copy in this parameter
326 * @param int len - length of the output string
327 *
328 * @return The status of the operation.
329 * @retval RETURN_OK if successful
330 * @retval RETURN_ERR if any error is detected
331 *
332 * @execution Synchronous.
333 * @sideeffect None.
334 *
335 */
336 
337 void _get_shell_outputbuffer(char * cmd, char * out, int len);
338 
339 /**
340 * @description This HAL utility is used store the VLAN ID, Group Name configuration.
341 * @param char *groupName - bridge name
342 * @param char *vlanID - VLAND ID
343 *
344 * @return The status of the operation.
345 * @retval RETURN_OK if successful
346 * @retval RETURN_ERR if any error is detected
347 *
348 * @execution Synchronous.
349 * @sideeffect None.
350 *
351 */
352 
353 int insert_VLAN_ConfigEntry(char *groupName, char *vlanID);
354 
355 /**
356 * @description This HAL utility is used delete the VLAN ID, Group Name configuration
357 * @param char *groupName - bridge name
358 *
359 * @return The status of the operation.
360 * @retval RETURN_OK if successful
361 * @retval RETURN_ERR if any error is detected
362 *
363 * @execution Synchronous.
364 * @sideeffect None.
365 *
366 */
367 
369 
370 
371 /**
372 * @description This HAL utility is used delete the VLAN ID, Group Name configuration from link
373 * @param char *groupName - bridge name
374 * @param char char *vlanID - VLANID
375 *
376 * @return The status of the operation.
377 * @retval RETURN_OK if successful
378 * @retval RETURN_ERR if any error is detected
379 *
380 * @execution Synchronous.
381 * @sideeffect None.
382 *
383 */
384 
385 int get_vlanId_for_GroupName(const char *groupName, char *vlanID);
386 
387 /**
388 * @description This HAL utility is used get the VLAN ID for corresponding Group Name from link
389 * @param None.
390 *
391 * @return The status of the operation.
392 * @retval RETURN_OK if successful
393 * @retval RETURN_ERR if any error is detected
394 *
395 * @execution Synchronous.
396 * @sideeffect None.
397 *
398 */
399 
401 
402 /** @} */ //END OF GROUP VLAN_HAL_APIS
403 
404 /*
405 Example usage on Puma6 platfom:
406  Private network group (vlan100)
407  brlan0 eth_1(external swith port 1), eth_2(port 2), eth_3(port 3), MoCA.100 (MoCA vlan100), ath0(2.4G vlan100), ath1 (5G vlan100)
408 
409 vlan_hal_addGroup("brlan0", "100"); //brctl addbr brlan0
410 vlan_hal_addInterface("brlan0", "l2sd0", NULL); //vconfig add l2sd0 100; brctl addif brlan0 l2sd0.100
411 
412 
413  Xfinity Home VLAN (vlan101)
414  brlan1 eth_4(port 4), MoCA.101(MoCA vlan101), ath2(2.4G vlan101), ath3 (5G vlan101)
415 
416 vlan_hal_addGroup("brlan1", "101"); //brctl addbr brlan1
417 vlan_hal_addInterface("brlan1", "l2sd0", NULL); //vconfig add l2sd0 100; brctl addif brlan1 l2sd0.101
418 
419 
420  Xfinity Wifi VLAN 2.4G (vlan102)
421  brlan2 gretap0.102 (GRE vlan102), MoCA.102(MoCA vlan102), ath4(2.4G vlan102)
422 
423 vlan_hal_addGroup("brlan2", "102"); //brctl addbr brlan2
424 vlan_hal_addInterface("brlan2", "l2sd0", NULL); //vconfig add l2sd0 102; brctl addif brlan1 l2sd0.102
425 vlan_hal_addInterface("brlan2", "gretap0", NULL); //vconfig add gretap0 102; brctl addif brlan1 gretap0.102
426 
427 
428  Xfinity Wifi VLAN 5G (vlan103)
429  brlan3 gretap0.103 (GRE vlan103), MoCA.103(MoCA vlan103), ath5(2.4G vlan103)
430 
431 vlan_hal_addGroup("brlan3", "103"); //brctl addbr brlan3
432 vlan_hal_addInterface("brlan3", "l2sd0", NULL); //vconfig add l2sd0 103; brctl addif brlan1 l2sd0.103
433 vlan_hal_addInterface("brlan3", "gretap0", NULL); //vconfig add gretap0 103; brctl addif brlan1 gretap0.103
434 
435 */
436 #endif /*__VLAN_HAL_H__*/
_is_this_interface_available_in_linux_bridge
int _is_this_interface_available_in_linux_bridge(char *if_name, char *vlanID)
_vlan_vlanidconfiguration::groupName
char groupName[32]
Definition: vlan_hal.h:154
vlan_hal_addInterface
int vlan_hal_addInterface(const char *groupName, const char *ifName, const char *vlanID)
vlan_hal_delInterface
int vlan_hal_delInterface(const char *groupName, const char *ifName, const char *vlanID)
_vlan_vlanidconfiguration
Definition: vlan_hal.h:148
vlan_hal_printAllGroup
int vlan_hal_printAllGroup()
vlan_hal_printGroup
int vlan_hal_printGroup(const char *groupName)
VLAN_HAL_MAX_VLANID_TEXT_LENGTH
#define VLAN_HAL_MAX_VLANID_TEXT_LENGTH
Definition: vlan_hal.h:134
VLAN_HAL_MAX_VLANGROUP_TEXT_LENGTH
#define VLAN_HAL_MAX_VLANGROUP_TEXT_LENGTH
Definition: vlan_hal.h:133
_vlan_vlanidconfiguration::nextlink
struct _vlan_vlanidconfiguration * nextlink
Definition: vlan_hal.h:156
_get_shell_outputbuffer
void _get_shell_outputbuffer(char *cmd, char *out, int len)
vlan_hal_addGroup
int vlan_hal_addGroup(const char *groupName, const char *default_vlanID)
vlan_hal_delGroup
int vlan_hal_delGroup(const char *groupName)
_is_this_interface_available_in_given_linux_bridge
int _is_this_interface_available_in_given_linux_bridge(char *if_name, char *br_name, char *vlanID)
_is_this_group_available_in_linux_bridge
int _is_this_group_available_in_linux_bridge(char *br_name)
vlan_vlanidconfiguration_t
struct _vlan_vlanidconfiguration vlan_vlanidconfiguration_t
get_vlanId_for_GroupName
int get_vlanId_for_GroupName(const char *groupName, char *vlanID)
insert_VLAN_ConfigEntry
int insert_VLAN_ConfigEntry(char *groupName, char *vlanID)
_vlan_vlanidconfiguration::vlanID
char vlanID[32]
Definition: vlan_hal.h:155
delete_VLAN_ConfigEntry
int delete_VLAN_ConfigEntry(char *groupName)
print_all_vlanId_Configuration
int print_all_vlanId_Configuration(void)
vlan_hal_delete_all_Interfaces
int vlan_hal_delete_all_Interfaces(const char *groupName)