blob: c7ee7444668f5b829352e645eedab362e3fe908d [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/**=============================================================================
23 wlan_hdd_dp_utils.c
24
25 \brief Utility functions for data path module
26
27 Description...
28 Copyright 2008 (c) Qualcomm, Incorporated.
29 All Rights Reserved.
30 Qualcomm Confidential and Proprietary.
31
32 ==============================================================================**/
33/* $HEADER$ */
34
35/**-----------------------------------------------------------------------------
36 Include files
37 ----------------------------------------------------------------------------*/
38#include <wlan_hdd_dp_utils.h>
39
40/**-----------------------------------------------------------------------------
41 Preprocessor definitions and constants
42 ----------------------------------------------------------------------------*/
43
44/**-----------------------------------------------------------------------------
45 Type declarations
46 ----------------------------------------------------------------------------*/
47
48/**-----------------------------------------------------------------------------
49 Function declarations and documenation
50 ----------------------------------------------------------------------------*/
51
52
53VOS_STATUS hdd_list_insert_front( hdd_list_t *pList, hdd_list_node_t *pNode )
54{
55 list_add( pNode, &pList->anchor );
56 pList->count++;
57 return VOS_STATUS_SUCCESS;
58}
59
60VOS_STATUS hdd_list_insert_back( hdd_list_t *pList, hdd_list_node_t *pNode )
61{
62 list_add_tail( pNode, &pList->anchor );
63 pList->count++;
64 return VOS_STATUS_SUCCESS;
65}
66
67VOS_STATUS hdd_list_insert_back_size( hdd_list_t *pList, hdd_list_node_t *pNode, v_SIZE_t *pSize )
68{
69 list_add_tail( pNode, &pList->anchor );
70 pList->count++;
71 *pSize = pList->count;
72 return VOS_STATUS_SUCCESS;
73}
74
75VOS_STATUS hdd_list_remove_front( hdd_list_t *pList, hdd_list_node_t **ppNode )
76{
77 struct list_head * listptr;
78
79 if ( list_empty( &pList->anchor ) )
80 {
81 return VOS_STATUS_E_EMPTY;
82 }
83
84 listptr = pList->anchor.next;
85 *ppNode = listptr;
86 list_del(pList->anchor.next);
87 pList->count--;
88
89 return VOS_STATUS_SUCCESS;
90}
91
92VOS_STATUS hdd_list_remove_back( hdd_list_t *pList, hdd_list_node_t **ppNode )
93{
94 struct list_head * listptr;
95
96 if ( list_empty( &pList->anchor ) )
97 {
98 return VOS_STATUS_E_EMPTY;
99 }
100
101 listptr = pList->anchor.prev;
102 *ppNode = listptr;
103 list_del(pList->anchor.prev);
104 pList->count--;
105
106 return VOS_STATUS_SUCCESS;
107}
108
109VOS_STATUS hdd_list_remove_node( hdd_list_t *pList,
110 hdd_list_node_t *pNodeToRemove )
111{
112 hdd_list_node_t *tmp;
113 int found = 0;
114
115 if ( list_empty( &pList->anchor ) )
116 {
117 return VOS_STATUS_E_EMPTY;
118 }
119
120 // verify that pNodeToRemove is indeed part of list pList
121 list_for_each(tmp, &pList->anchor)
122 {
123 if (tmp == pNodeToRemove)
124 {
125 found = 1;
126 break;
127 }
128 }
129 if (found == 0)
130 return VOS_STATUS_E_INVAL;
131
132 list_del(pNodeToRemove);
133 pList->count--;
134
135 return VOS_STATUS_SUCCESS;
136}
137
138VOS_STATUS hdd_list_peek_front( hdd_list_t *pList,
139 hdd_list_node_t **ppNode )
140{
141 struct list_head * listptr;
142 if ( list_empty( &pList->anchor ) )
143 {
144 return VOS_STATUS_E_EMPTY;
145 }
146
147 listptr = pList->anchor.next;
148 *ppNode = listptr;
149 return VOS_STATUS_SUCCESS;
150}
151
152VOS_STATUS hdd_list_peek_next( hdd_list_t *pList, hdd_list_node_t *pNode,
153 hdd_list_node_t **ppNode )
154{
155 struct list_head * listptr;
156 int found = 0;
157 hdd_list_node_t *tmp;
158
159 if ( ( pList == NULL) || ( pNode == NULL) || (ppNode == NULL))
160 {
161 return VOS_STATUS_E_FAULT;
162 }
163
164 if ( list_empty(&pList->anchor) )
165 {
166 return VOS_STATUS_E_EMPTY;
167 }
168
169 // verify that pNode is indeed part of list pList
170 list_for_each(tmp, &pList->anchor)
171 {
172 if (tmp == pNode)
173 {
174 found = 1;
175 break;
176 }
177 }
178
179 if (found == 0)
180 {
181 return VOS_STATUS_E_INVAL;
182 }
183
184 listptr = pNode->next;
185 if (listptr == &pList->anchor)
186 {
187 return VOS_STATUS_E_EMPTY;
188 }
189
190 *ppNode = listptr;
191
192 return VOS_STATUS_SUCCESS;
193}
194
195VOS_STATUS hdd_string_to_hex( char *pSrcMac, int length, char *pDescMac )
196{
197 int i;
198 int k;
199 char temp[3] = {0};
200
201 //18 is MAC Address length plus the colons
202 if ( !pSrcMac && (length > 18 || length < 18) )
203 {
204 return VOS_STATUS_E_FAILURE;
205 }
206 i = k = 0;
207 while ( i < length )
208 {
209 memcpy(temp, pSrcMac+i, 2);
210 pDescMac[k++] = (char)simple_strtoul (temp, NULL, 16);
211 i += 3;
212 }
213
214 return VOS_STATUS_SUCCESS;
215}
216