auth-proto.h (3127B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #include <errno.h> 24 25 struct auth_proto { 26 bool (*start)(struct auth_proto *ap); 27 void (*free)(struct auth_proto *ap); 28 /* 29 * Callback to receive an Authenticate frame. auth-protos should 30 * return error codes consistent with one another as some are treated 31 * specially: 32 * 33 * 0 indicates success, and that a state transition occurred. 34 * -ENOMSG or -EBADMSG indicates the message should be ignored silently 35 * -EAGAIN indicates a retry, and no state transition occurred. Any 36 * retry is handled by the auth-proto internally 37 * -EPROTO indicates a fatal error 38 * Any other < 0 return will be treated as a fatal error 39 * > 0 indicates a fatal error with status code. This only applies to 40 * non-sta cases as non-zero status codes are rejected by the 41 * kernel when in station mode. 42 */ 43 int (*rx_authenticate)(struct auth_proto *driver, 44 const uint8_t *frame, size_t len); 45 int (*rx_associate)(struct auth_proto *driver, 46 const uint8_t *frame, size_t len); 47 int (*rx_oci)(struct auth_proto *driver); 48 bool (*auth_timeout)(struct auth_proto *ap); 49 bool (*assoc_timeout)(struct auth_proto *ap); 50 uint8_t prev_bssid[6]; 51 }; 52 53 static inline void auth_proto_free(struct auth_proto *ap) 54 { 55 if (ap && ap->free) 56 ap->free(ap); 57 } 58 59 static inline bool auth_proto_start(struct auth_proto *ap) 60 { 61 if (ap && ap->start) 62 return ap->start(ap); 63 64 return false; 65 } 66 67 static inline int auth_proto_rx_authenticate(struct auth_proto *ap, 68 const uint8_t *frame, 69 size_t frame_len) 70 { 71 if (ap && ap->rx_authenticate) 72 return ap->rx_authenticate(ap, frame, frame_len); 73 74 return -ENOTSUP; 75 } 76 77 static inline int auth_proto_rx_associate(struct auth_proto *ap, 78 const uint8_t *frame, 79 size_t frame_len) 80 { 81 if (ap && ap->rx_associate) 82 return ap->rx_associate(ap, frame, frame_len); 83 84 return -ENOTSUP; 85 } 86 87 static inline bool auth_proto_auth_timeout(struct auth_proto *ap) 88 { 89 if (ap && ap->auth_timeout) 90 return ap->auth_timeout(ap); 91 92 return false; 93 } 94 95 static inline bool auth_proto_assoc_timeout(struct auth_proto *ap) 96 { 97 if (ap && ap->assoc_timeout) 98 return ap->assoc_timeout(ap); 99 100 return false; 101 } 102 103 static inline int auth_proto_rx_oci(struct auth_proto *ap) 104 { 105 if (ap && ap->rx_oci) 106 return ap->rx_oci(ap); 107 108 return -ENOTSUP; 109 }