blob: 7a18c4e773d803a3fd47eb2f846acc7e4c579bb6 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lam842dad02014-02-18 18:44:02 -08002 * Copyright (c) 2012-2013 The Linux Foundation. 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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam842dad02014-02-18 18:44:02 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson295189b2012-06-20 16:38:30 -070028/**=============================================================================
29 wlan_hdd_dp_utils.c
30
31 \brief Utility functions for data path module
32
33 Description...
Jeff Johnson295189b2012-06-20 16:38:30 -070034
35 ==============================================================================**/
36/* $HEADER$ */
37
38/**-----------------------------------------------------------------------------
39 Include files
40 ----------------------------------------------------------------------------*/
41#include <wlan_hdd_dp_utils.h>
42
43/**-----------------------------------------------------------------------------
44 Preprocessor definitions and constants
45 ----------------------------------------------------------------------------*/
46
47/**-----------------------------------------------------------------------------
48 Type declarations
49 ----------------------------------------------------------------------------*/
50
51/**-----------------------------------------------------------------------------
52 Function declarations and documenation
53 ----------------------------------------------------------------------------*/
54
55
56VOS_STATUS hdd_list_insert_front( hdd_list_t *pList, hdd_list_node_t *pNode )
57{
58 list_add( pNode, &pList->anchor );
59 pList->count++;
60 return VOS_STATUS_SUCCESS;
61}
62
63VOS_STATUS hdd_list_insert_back( hdd_list_t *pList, hdd_list_node_t *pNode )
64{
65 list_add_tail( pNode, &pList->anchor );
66 pList->count++;
67 return VOS_STATUS_SUCCESS;
68}
69
70VOS_STATUS hdd_list_insert_back_size( hdd_list_t *pList, hdd_list_node_t *pNode, v_SIZE_t *pSize )
71{
72 list_add_tail( pNode, &pList->anchor );
73 pList->count++;
74 *pSize = pList->count;
75 return VOS_STATUS_SUCCESS;
76}
77
78VOS_STATUS hdd_list_remove_front( hdd_list_t *pList, hdd_list_node_t **ppNode )
79{
80 struct list_head * listptr;
81
82 if ( list_empty( &pList->anchor ) )
83 {
84 return VOS_STATUS_E_EMPTY;
85 }
86
87 listptr = pList->anchor.next;
88 *ppNode = listptr;
89 list_del(pList->anchor.next);
90 pList->count--;
91
92 return VOS_STATUS_SUCCESS;
93}
94
95VOS_STATUS hdd_list_remove_back( hdd_list_t *pList, hdd_list_node_t **ppNode )
96{
97 struct list_head * listptr;
98
99 if ( list_empty( &pList->anchor ) )
100 {
101 return VOS_STATUS_E_EMPTY;
102 }
103
104 listptr = pList->anchor.prev;
105 *ppNode = listptr;
106 list_del(pList->anchor.prev);
107 pList->count--;
108
109 return VOS_STATUS_SUCCESS;
110}
111
112VOS_STATUS hdd_list_remove_node( hdd_list_t *pList,
113 hdd_list_node_t *pNodeToRemove )
114{
115 hdd_list_node_t *tmp;
116 int found = 0;
117
118 if ( list_empty( &pList->anchor ) )
119 {
120 return VOS_STATUS_E_EMPTY;
121 }
122
123 // verify that pNodeToRemove is indeed part of list pList
124 list_for_each(tmp, &pList->anchor)
125 {
126 if (tmp == pNodeToRemove)
127 {
128 found = 1;
129 break;
130 }
131 }
132 if (found == 0)
133 return VOS_STATUS_E_INVAL;
134
135 list_del(pNodeToRemove);
136 pList->count--;
137
138 return VOS_STATUS_SUCCESS;
139}
140
141VOS_STATUS hdd_list_peek_front( hdd_list_t *pList,
142 hdd_list_node_t **ppNode )
143{
144 struct list_head * listptr;
145 if ( list_empty( &pList->anchor ) )
146 {
147 return VOS_STATUS_E_EMPTY;
148 }
149
150 listptr = pList->anchor.next;
151 *ppNode = listptr;
152 return VOS_STATUS_SUCCESS;
153}
154
155VOS_STATUS hdd_list_peek_next( hdd_list_t *pList, hdd_list_node_t *pNode,
156 hdd_list_node_t **ppNode )
157{
158 struct list_head * listptr;
159 int found = 0;
160 hdd_list_node_t *tmp;
161
162 if ( ( pList == NULL) || ( pNode == NULL) || (ppNode == NULL))
163 {
164 return VOS_STATUS_E_FAULT;
165 }
166
167 if ( list_empty(&pList->anchor) )
168 {
169 return VOS_STATUS_E_EMPTY;
170 }
171
172 // verify that pNode is indeed part of list pList
173 list_for_each(tmp, &pList->anchor)
174 {
175 if (tmp == pNode)
176 {
177 found = 1;
178 break;
179 }
180 }
181
182 if (found == 0)
183 {
184 return VOS_STATUS_E_INVAL;
185 }
186
187 listptr = pNode->next;
188 if (listptr == &pList->anchor)
189 {
190 return VOS_STATUS_E_EMPTY;
191 }
192
193 *ppNode = listptr;
194
195 return VOS_STATUS_SUCCESS;
196}
197
198VOS_STATUS hdd_string_to_hex( char *pSrcMac, int length, char *pDescMac )
199{
200 int i;
201 int k;
202 char temp[3] = {0};
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -0800203 int rv;
Jeff Johnson295189b2012-06-20 16:38:30 -0700204
205 //18 is MAC Address length plus the colons
206 if ( !pSrcMac && (length > 18 || length < 18) )
207 {
208 return VOS_STATUS_E_FAILURE;
209 }
210 i = k = 0;
211 while ( i < length )
212 {
213 memcpy(temp, pSrcMac+i, 2);
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -0800214 rv = kstrtou8(temp, 16, &pDescMac[k++]);
215 if (rv < 0)
216 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700217 i += 3;
218 }
219
220 return VOS_STATUS_SUCCESS;
221}
222