Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Jeff Johnson | 32d95a3 | 2012-09-10 13:15:23 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 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 | * Woodside Networks, Inc proprietary. All rights reserved. |
| 24 | * $File: //depot/software/projects/feature_branches/gen5_phase1/os/linux/classic/ap/apps/include/aniSsmReplayCtr.h $ |
| 25 | * |
| 26 | * Contains declarations of various utilities for SSM replay counter |
| 27 | * module. |
| 28 | * |
| 29 | * Author: Mayank D. Upadhyay |
| 30 | * Date: 15-June-2003 |
| 31 | * History:- |
| 32 | * Date Modified by Modification Information |
| 33 | * ------------------------------------------------------ |
| 34 | * |
| 35 | */ |
| 36 | #ifndef _ANI_SSM_REPLAY_CTR_H_ |
| 37 | #define _ANI_SSM_REPLAY_CTR_H_ |
| 38 | |
| 39 | #include "vos_types.h" |
| 40 | #include <bapRsnAsfPacket.h> |
| 41 | |
| 42 | /* |
| 43 | * Opaque replay counter type. Does TX and RX side replay counter |
| 44 | * tracking. On the TX side, it returns monotonicall increasing values |
| 45 | * of the counter and checks that the peer returned a value matching |
| 46 | * the one we sent. On the RX side, it makes sure that the peer sent a |
| 47 | * replay counter greater than the last one seen (excepting for the |
| 48 | * first time a check is made which the application has to special case.) |
| 49 | */ |
| 50 | typedef struct sAniSsmReplayCtr tAniSsmReplayCtr; |
| 51 | |
| 52 | /** |
| 53 | * aniSsmReplayCtrCreate |
| 54 | * |
| 55 | * Creates a replay counter and initializes it for first time |
| 56 | * use. The initialization can be done randomly or with a passed in |
| 57 | * value like 0. In case this is going to be used on the RX side, it |
| 58 | * doesn't matter what the initiaalization is and can be optimized to |
| 59 | * a fixed value so as to avoid the overhead of obtaining a random |
| 60 | * value. |
| 61 | * |
| 62 | * @param ctrPtr a pointer that will be set to the newly allocated |
| 63 | * counter if the operation succeeds |
| 64 | * @param size the number of bytes that are desired in the counter |
| 65 | * @param initValue if this is negative and size is greater than 4, |
| 66 | * the initialization is done randomly. Otherwise, these bytes are |
| 67 | * copied into the least significant four or less octets of the |
| 68 | * counter, depending on the size of the counter. i.e., if the counter |
| 69 | * is only 2B, then the least significant 2B of initValue will be |
| 70 | * copied over. |
| 71 | * |
| 72 | * @return ANI_OK if the operation succeeds |
| 73 | */ |
| 74 | int |
| 75 | aniSsmReplayCtrCreate(v_U32_t cryptHandle, tAniSsmReplayCtr **ctrPtr, |
| 76 | v_U8_t size, |
| 77 | int initValue); |
| 78 | |
| 79 | /** |
| 80 | * aniSsmReplayCtrCmp |
| 81 | * |
| 82 | * Used to check if the passed in value is greater |
| 83 | * than, less than, or the same as the previous value. |
| 84 | * |
| 85 | * Can be used on the TX side to determine if the response to a |
| 86 | * request contains the same counter as the one in the request. |
| 87 | * |
| 88 | * Can be used on the RX side to determine if the request has a |
| 89 | * counter greater than the previous request, or if this is a |
| 90 | * retransmission of the previous request. The application should |
| 91 | * special-case the first time this is called on the RX side. |
| 92 | * |
| 93 | * @param ctr the current replay counter |
| 94 | * @param value the value to check against |
| 95 | * |
| 96 | * @return A negative error code if value is less than the |
| 97 | * current value of the counter, zero if they are the same, and a |
| 98 | * positive value if the current value is greater than that of the |
| 99 | * counter. |
| 100 | */ |
| 101 | int |
| 102 | aniSsmReplayCtrCmp(tAniSsmReplayCtr *ctr, |
| 103 | v_U8_t *value); |
| 104 | |
| 105 | /** |
| 106 | * aniSsmReplayCtrUpdate |
| 107 | * |
| 108 | * Used on the RX side to update the value of the current replay |
| 109 | * counter to that received in the next request. Typically this is |
| 110 | * called after it is determined that this is not a retransmission, |
| 111 | * and some sort of integrity checking is done on it. |
| 112 | * |
| 113 | * @param ctr the current replay counter |
| 114 | * @param value the value that it should be set to |
| 115 | * |
| 116 | * @return ANI_OK if the operation succeeds |
| 117 | */ |
| 118 | int |
| 119 | aniSsmReplayCtrUpdate(tAniSsmReplayCtr *ctr, |
| 120 | v_U8_t *value); |
| 121 | |
| 122 | /** |
| 123 | * aniSsmReplayCtrNext |
| 124 | * |
| 125 | * Used on the RX side to obtain the next value that should be sent |
| 126 | * with a request. After this call, the current value is incremented |
| 127 | * by one. |
| 128 | * |
| 129 | * @param ctr the current replay counter |
| 130 | * @param value where the next counter value should be copied |
| 131 | * into. The caller must allocated enough storage for this. |
| 132 | * |
| 133 | * @return ANI_OK if the operation succeeds |
| 134 | */ |
| 135 | int |
| 136 | aniSsmReplayCtrNext(tAniSsmReplayCtr *ctr, |
| 137 | v_U8_t *value); |
| 138 | |
| 139 | /** |
| 140 | * aniSsmReplayCtrFree |
| 141 | * |
| 142 | * Frees the replay counter context. |
| 143 | * |
| 144 | * @param ctr the replay counter to free. |
| 145 | * |
| 146 | * @return ANI_OK if the operation succeeds |
| 147 | */ |
| 148 | int |
| 149 | aniSsmReplayCtrFree(tAniSsmReplayCtr *ctr); |
| 150 | |
| 151 | #endif //_ANI_SSM_REPLAY_CTR_H_ |