Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Kiet Lam | 842dad0 | 2014-02-18 18:44:02 -0800 | [diff] [blame] | 2 | * 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 Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 20 | */ |
Kiet Lam | 842dad0 | 2014-02-18 18:44:02 -0800 | [diff] [blame] | 21 | |
| 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 Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 28 | /**============================================================================= |
| 29 | wlan_hdd_dp_utils.c |
| 30 | |
| 31 | \brief Utility functions for data path module |
| 32 | |
| 33 | Description... |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 34 | |
| 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 | |
| 56 | VOS_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 | |
| 63 | VOS_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 | |
| 70 | VOS_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 | |
| 78 | VOS_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 | |
| 95 | VOS_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 | |
| 112 | VOS_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 | |
| 141 | VOS_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 | |
| 155 | VOS_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 | |
| 198 | VOS_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 Koyyalamudi | d8ac866 | 2012-11-06 19:04:56 -0800 | [diff] [blame] | 203 | int rv; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 204 | |
| 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 Koyyalamudi | d8ac866 | 2012-11-06 19:04:56 -0800 | [diff] [blame] | 214 | rv = kstrtou8(temp, 16, &pDescMac[k++]); |
| 215 | if (rv < 0) |
| 216 | return VOS_STATUS_E_FAILURE; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 217 | i += 3; |
| 218 | } |
| 219 | |
| 220 | return VOS_STATUS_SUCCESS; |
| 221 | } |
| 222 | |