blob: b1a9ecf602b96f10f0f4d9a4113a3fdd6648dfe1 [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...
34 Copyright 2008 (c) Qualcomm, Incorporated.
35 All Rights Reserved.
36 Qualcomm Confidential and Proprietary.
37
38 ==============================================================================**/
39/* $HEADER$ */
40
41/**-----------------------------------------------------------------------------
42 Include files
43 ----------------------------------------------------------------------------*/
44#include <wlan_hdd_dp_utils.h>
45
46/**-----------------------------------------------------------------------------
47 Preprocessor definitions and constants
48 ----------------------------------------------------------------------------*/
49
50/**-----------------------------------------------------------------------------
51 Type declarations
52 ----------------------------------------------------------------------------*/
53
54/**-----------------------------------------------------------------------------
55 Function declarations and documenation
56 ----------------------------------------------------------------------------*/
57
58
59VOS_STATUS hdd_list_insert_front( hdd_list_t *pList, hdd_list_node_t *pNode )
60{
61 list_add( pNode, &pList->anchor );
62 pList->count++;
63 return VOS_STATUS_SUCCESS;
64}
65
66VOS_STATUS hdd_list_insert_back( hdd_list_t *pList, hdd_list_node_t *pNode )
67{
68 list_add_tail( pNode, &pList->anchor );
69 pList->count++;
70 return VOS_STATUS_SUCCESS;
71}
72
73VOS_STATUS hdd_list_insert_back_size( hdd_list_t *pList, hdd_list_node_t *pNode, v_SIZE_t *pSize )
74{
75 list_add_tail( pNode, &pList->anchor );
76 pList->count++;
77 *pSize = pList->count;
78 return VOS_STATUS_SUCCESS;
79}
80
81VOS_STATUS hdd_list_remove_front( hdd_list_t *pList, hdd_list_node_t **ppNode )
82{
83 struct list_head * listptr;
84
85 if ( list_empty( &pList->anchor ) )
86 {
87 return VOS_STATUS_E_EMPTY;
88 }
89
90 listptr = pList->anchor.next;
91 *ppNode = listptr;
92 list_del(pList->anchor.next);
93 pList->count--;
94
95 return VOS_STATUS_SUCCESS;
96}
97
98VOS_STATUS hdd_list_remove_back( hdd_list_t *pList, hdd_list_node_t **ppNode )
99{
100 struct list_head * listptr;
101
102 if ( list_empty( &pList->anchor ) )
103 {
104 return VOS_STATUS_E_EMPTY;
105 }
106
107 listptr = pList->anchor.prev;
108 *ppNode = listptr;
109 list_del(pList->anchor.prev);
110 pList->count--;
111
112 return VOS_STATUS_SUCCESS;
113}
114
115VOS_STATUS hdd_list_remove_node( hdd_list_t *pList,
116 hdd_list_node_t *pNodeToRemove )
117{
118 hdd_list_node_t *tmp;
119 int found = 0;
120
121 if ( list_empty( &pList->anchor ) )
122 {
123 return VOS_STATUS_E_EMPTY;
124 }
125
126 // verify that pNodeToRemove is indeed part of list pList
127 list_for_each(tmp, &pList->anchor)
128 {
129 if (tmp == pNodeToRemove)
130 {
131 found = 1;
132 break;
133 }
134 }
135 if (found == 0)
136 return VOS_STATUS_E_INVAL;
137
138 list_del(pNodeToRemove);
139 pList->count--;
140
141 return VOS_STATUS_SUCCESS;
142}
143
144VOS_STATUS hdd_list_peek_front( hdd_list_t *pList,
145 hdd_list_node_t **ppNode )
146{
147 struct list_head * listptr;
148 if ( list_empty( &pList->anchor ) )
149 {
150 return VOS_STATUS_E_EMPTY;
151 }
152
153 listptr = pList->anchor.next;
154 *ppNode = listptr;
155 return VOS_STATUS_SUCCESS;
156}
157
158VOS_STATUS hdd_list_peek_next( hdd_list_t *pList, hdd_list_node_t *pNode,
159 hdd_list_node_t **ppNode )
160{
161 struct list_head * listptr;
162 int found = 0;
163 hdd_list_node_t *tmp;
164
165 if ( ( pList == NULL) || ( pNode == NULL) || (ppNode == NULL))
166 {
167 return VOS_STATUS_E_FAULT;
168 }
169
170 if ( list_empty(&pList->anchor) )
171 {
172 return VOS_STATUS_E_EMPTY;
173 }
174
175 // verify that pNode is indeed part of list pList
176 list_for_each(tmp, &pList->anchor)
177 {
178 if (tmp == pNode)
179 {
180 found = 1;
181 break;
182 }
183 }
184
185 if (found == 0)
186 {
187 return VOS_STATUS_E_INVAL;
188 }
189
190 listptr = pNode->next;
191 if (listptr == &pList->anchor)
192 {
193 return VOS_STATUS_E_EMPTY;
194 }
195
196 *ppNode = listptr;
197
198 return VOS_STATUS_SUCCESS;
199}
200
201VOS_STATUS hdd_string_to_hex( char *pSrcMac, int length, char *pDescMac )
202{
203 int i;
204 int k;
205 char temp[3] = {0};
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -0800206 int rv;
Jeff Johnson295189b2012-06-20 16:38:30 -0700207
208 //18 is MAC Address length plus the colons
209 if ( !pSrcMac && (length > 18 || length < 18) )
210 {
211 return VOS_STATUS_E_FAILURE;
212 }
213 i = k = 0;
214 while ( i < length )
215 {
216 memcpy(temp, pSrcMac+i, 2);
Madan Mohan Koyyalamudid8ac8662012-11-06 19:04:56 -0800217 rv = kstrtou8(temp, 16, &pDescMac[k++]);
218 if (rv < 0)
219 return VOS_STATUS_E_FAILURE;
Jeff Johnson295189b2012-06-20 16:38:30 -0700220 i += 3;
221 }
222
223 return VOS_STATUS_SUCCESS;
224}
225