1 /* 2 * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: Public APIs for crypto service 21 */ 22 #ifndef _WLAN_CRYPTO_GLOBAL_API_H_ 23 #define _WLAN_CRYPTO_GLOBAL_API_H_ 24 25 26 /** 27 * wlan_crypto_set_vdev_param - called by ucfg to set crypto param 28 * @vdev: vdev 29 * @param: param to be set. 30 * @value: value 31 * 32 * This function gets called from ucfg to set param 33 * 34 * Return: QDF_STATUS_SUCCESS - in case of success 35 */ 36 QDF_STATUS wlan_crypto_set_vdev_param(struct wlan_objmgr_vdev *vdev, 37 wlan_crypto_param_type param, 38 uint32_t value); 39 40 /** 41 * wlan_crypto_set_peer_param - called by ucfg to set crypto param 42 * 43 * @peer: peer 44 * @param: param to be set. 45 * @value: value 46 * 47 * This function gets called from ucfg to set param 48 * 49 * Return: QDF_STATUS_SUCCESS - in case of success 50 */ 51 QDF_STATUS wlan_crypto_set_peer_param(struct wlan_objmgr_peer *peer, 52 wlan_crypto_param_type param, 53 uint32_t value); 54 55 /** 56 * wlan_crypto_get_param - called by ucfg to get crypto param 57 * @vdev: vdev 58 * @param: param to be get. 59 * 60 * This function gets called from ucfg to get param 61 * 62 * Return: value or -1 for failure 63 */ 64 int32_t wlan_crypto_get_param(struct wlan_objmgr_vdev *vdev, 65 wlan_crypto_param_type param); 66 /** 67 * wlan_crypto_get_peer_param - called by ucfg to get crypto peer param 68 * @peer: peer 69 * @param: param to be get. 70 * 71 * This function gets called from ucfg to get peer param 72 * 73 * Return: value or -1 for failure 74 */ 75 int32_t wlan_crypto_get_peer_param(struct wlan_objmgr_peer *peer, 76 wlan_crypto_param_type param); 77 78 /** 79 * wlan_crypto_is_htallowed - called by ucfg to check if HT rates is allowed 80 * @vdev: Vdev 81 * @peer: Peer 82 * 83 * This function is called to check if HT rates is allowed 84 * 85 * Return: 0 for not allowed and +ve for allowed 86 */ 87 uint8_t wlan_crypto_is_htallowed(struct wlan_objmgr_vdev *vdev, 88 struct wlan_objmgr_peer *peer); 89 /** 90 * wlan_crypto_setkey - called by ucfg to setkey 91 * @vdev: vdev 92 * @req_key: req_key with cipher type, key macaddress 93 * 94 * This function gets called from ucfg to sey key 95 * 96 * Return: QDF_STATUS_SUCCESS - in case of success 97 */ 98 QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev, 99 struct wlan_crypto_req_key *req_key); 100 101 /** 102 * wlan_crypto_getkey - called by ucfg to get key 103 * @vdev: vdev 104 * @req_key: key value will be copied in this req_key 105 * @mac_address: mac address of the peer for unicast key 106 * or broadcast address if group key is requested. 107 * 108 * This function gets called from ucfg to get key 109 * 110 * Return: QDF_STATUS_SUCCESS - in case of success 111 */ 112 QDF_STATUS wlan_crypto_getkey(struct wlan_objmgr_vdev *vdev, 113 struct wlan_crypto_req_key *req_key, 114 uint8_t *mac_addr); 115 116 /** 117 * wlan_crypto_delkey - called by ucfg to delete key 118 * @vdev: vdev 119 * @mac_address: mac address of the peer for unicast key 120 * or broadcast address if group key is deleted. 121 * @key_idx: key index to be deleted 122 * 123 * This function gets called from ucfg to delete key 124 * 125 * Return: QDF_STATUS_SUCCESS - in case of success 126 */ 127 QDF_STATUS wlan_crypto_delkey(struct wlan_objmgr_vdev *vdev, 128 uint8_t *macaddr, 129 uint8_t key_idx); 130 131 /** 132 * wlan_crypto_default_key - called by ucfg to set default tx key 133 * @vdev: vdev 134 * @mac_address: mac address of the peer for unicast key 135 * or broadcast address if group key need to made default. 136 * @key_idx: key index to be made as default key 137 * @unicast: is key was unicast or group key. 138 * 139 * This function gets called from ucfg to set default key 140 * 141 * Return: QDF_STATUS_SUCCESS - in case of success 142 */ 143 QDF_STATUS wlan_crypto_default_key(struct wlan_objmgr_vdev *vdev, 144 uint8_t *macaddr, 145 uint8_t key_idx, 146 bool unicast); 147 148 /** 149 * wlan_crypto_encap - called by mgmt for encap the frame based on cipher 150 * @vdev: vdev 151 * @wbuf: wbuf 152 * @macaddr: macaddr 153 * @encapdone: is encapdone already or not. 154 * 155 * This function gets called from mgmt txrx to encap frame. 156 * 157 * Return: QDF_STATUS_SUCCESS - in case of success 158 */ 159 QDF_STATUS wlan_crypto_encap(struct wlan_objmgr_vdev *vdev, 160 qdf_nbuf_t wbuf, 161 uint8_t *macaddr, 162 uint8_t encapdone); 163 164 /** 165 * wlan_crypto_decap - called by mgmt for decap the frame based on cipher 166 * @vdev: vdev 167 * @wbuf: wbuf 168 * @macaddr: macaddr 169 * @tid: tid of the packet. 170 * 171 * This function gets called from mgmt txrx to decap frame. 172 * 173 * Return: QDF_STATUS_SUCCESS - in case of success 174 */ 175 QDF_STATUS wlan_crypto_decap(struct wlan_objmgr_vdev *vdev, 176 qdf_nbuf_t wbuf, 177 uint8_t *macaddr, 178 uint8_t tid); 179 180 /** 181 * wlan_crypto_enmic - called by mgmt for adding mic in frame based on cipher 182 * @vdev: vdev 183 * @wbuf: wbuf 184 * @macaddr: macaddr 185 * @encapdone: is encapdone already or not. 186 * 187 * This function gets called from mgmt txrx to adding mic to the frame. 188 * 189 * Return: QDF_STATUS_SUCCESS - in case of success 190 */ 191 QDF_STATUS wlan_crypto_enmic(struct wlan_objmgr_vdev *vdev, 192 qdf_nbuf_t wbuf, 193 uint8_t *macaddr, 194 uint8_t encapdone); 195 196 /** 197 * wlan_crypto_demic - called by mgmt for remove and check mic for 198 * the frame based on cipher 199 * @vdev: vdev 200 * @wbuf: wbuf 201 * @macaddr: macaddr 202 * @tid: tid of the frame 203 * @keyid: keyid in the received frame 204 * 205 * This function gets called from mgmt txrx to decap frame. 206 * 207 * Return: QDF_STATUS_SUCCESS - in case of success 208 */ 209 QDF_STATUS wlan_crypto_demic(struct wlan_objmgr_vdev *vdev, 210 qdf_nbuf_t wbuf, 211 uint8_t *macaddr, 212 uint8_t tid, 213 uint8_t keyid); 214 215 /** 216 * wlan_crypto_vdev_is_pmf_enabled - called to check is pmf enabled in vdev 217 * @vdev: vdev 218 * 219 * This function gets called to check is pmf enabled or not in vdev. 220 * 221 * Return: true or false 222 */ 223 bool wlan_crypto_vdev_is_pmf_enabled(struct wlan_objmgr_vdev *vdev); 224 225 /** 226 * wlan_crypto_is_pmf_enabled - called by mgmt txrx to check is pmf enabled 227 * @vdev: vdev 228 * @peer: peer 229 * 230 * This function gets called by mgmt txrx to check is pmf enabled or not. 231 * 232 * Return: true or false 233 */ 234 bool wlan_crypto_is_pmf_enabled(struct wlan_objmgr_vdev *vdev, 235 struct wlan_objmgr_peer *peer); 236 237 /** 238 * wlan_crypto_add_mmie - called by mgmt txrx to add mmie in frame 239 * @vdev: vdev 240 * @frm: frame starting pointer 241 * @len: length of the frame 242 * 243 * This function gets called by mgmt txrx to add mmie in frame 244 * 245 * Return: end of frame or NULL in case failure 246 */ 247 uint8_t *wlan_crypto_add_mmie(struct wlan_objmgr_vdev *vdev, 248 uint8_t *frm, 249 uint32_t len); 250 251 /** 252 * wlan_crypto_is_mmie_valid - called by mgmt txrx to check mmie of the frame 253 * @vdev: vdev 254 * @frm: frame starting pointer 255 * @efrm: end of frame pointer 256 * 257 * This function gets called by mgmt txrx to check mmie of the frame 258 * 259 * Return: true or false 260 */ 261 bool wlan_crypto_is_mmie_valid(struct wlan_objmgr_vdev *vdev, 262 uint8_t *frm, 263 uint8_t *efrm); 264 265 /** 266 * wlan_crypto_wpaie_check - called by mlme to check the wpaie 267 * @crypto params: crypto params 268 * @iebuf: ie buffer 269 * 270 * This function gets called by mlme to check the contents of wpa is 271 * matching with given crypto params 272 * 273 * Return: QDF_STATUS_SUCCESS - in case of success 274 */ 275 QDF_STATUS wlan_crypto_wpaie_check(struct wlan_crypto_params *, uint8_t *frm); 276 277 /** 278 * wlan_crypto_rsnie_check - called by mlme to check the rsnie 279 * @crypto params: crypto params 280 * @iebuf: ie buffer 281 * 282 * This function gets called by mlme to check the contents of rsn is 283 * matching with given crypto params 284 * 285 * Return: QDF_STATUS_SUCCESS - in case of success 286 */ 287 QDF_STATUS wlan_crypto_rsnie_check(struct wlan_crypto_params *, uint8_t *frm); 288 /** 289 * wlan_crypto_build_wpaie - called by mlme to build wpaie 290 * @vdev: vdev 291 * @iebuf: ie buffer 292 * 293 * This function gets called by mlme to build wpaie from given vdev 294 * 295 * Return: end of buffer 296 */ 297 uint8_t *wlan_crypto_build_wpaie(struct wlan_objmgr_vdev *vdev, 298 uint8_t *iebuf); 299 /** 300 * wlan_crypto_build_rsnie - called by mlme to build rsnie 301 * @vdev: vdev 302 * @iebuf: ie buffer 303 * 304 * This function gets called by mlme to build rsnie from given vdev 305 * 306 * Return: end of buffer 307 */ 308 uint8_t *wlan_crypto_build_rsnie(struct wlan_objmgr_vdev *vdev, 309 uint8_t *iebuf); 310 311 /** 312 * wlan_crypto_wapiie_check - called by mlme to check the wapiie 313 * @crypto params: crypto params 314 * @iebuf: ie buffer 315 * 316 * This function gets called by mlme to check the contents of wapi is 317 * matching with given crypto params 318 * 319 * Return: QDF_STATUS_SUCCESS - in case of success 320 */ 321 QDF_STATUS wlan_crypto_wapiie_check(struct wlan_crypto_params *crypto_params, 322 uint8_t *frm); 323 324 /** 325 * wlan_crypto_build_wapiie - called by mlme to build wapi ie 326 * @vdev: vdev 327 * @iebuf: ie buffer 328 * 329 * This function gets called by mlme to build wapi ie from given vdev 330 * 331 * Return: end of buffer 332 */ 333 uint8_t *wlan_crypto_build_wapiie(struct wlan_objmgr_vdev *vdev, 334 uint8_t *iebuf); 335 /** 336 * wlan_crypto_rsn_info - check is given params matching with vdev params. 337 * @vdev: vdev 338 * @crypto params: crypto params 339 * 340 * This function gets called by mlme to check is given params matching with 341 * vdev params. 342 * 343 * Return: true success or false for failure. 344 */ 345 bool wlan_crypto_rsn_info(struct wlan_objmgr_vdev *vdev, 346 struct wlan_crypto_params *crypto_params); 347 /** 348 * wlan_crypto_pn_check - called by data patch for PN check 349 * @vdev: vdev 350 * @wbuf: wbuf 351 * 352 * This function gets called by data patch for PN check 353 * 354 * Return: QDF_STATUS 355 */ 356 QDF_STATUS wlan_crypto_pn_check(struct wlan_objmgr_vdev *vdev, 357 qdf_nbuf_t wbuf); 358 /** 359 * wlan_crypto_vdev_get_crypto_params - called by mlme to get crypto params 360 * @vdev:vdev 361 * 362 * This function gets called by mlme to get crypto params 363 * 364 * Return: wlan_crypto_params or NULL in case of failure 365 */ 366 struct wlan_crypto_params *wlan_crypto_vdev_get_crypto_params( 367 struct wlan_objmgr_vdev *vdev); 368 /** 369 * wlan_crypto_peer_get_crypto_params - called by mlme to get crypto params 370 * @peer:peer 371 * 372 * This function gets called by mlme to get crypto params 373 * 374 * Return: wlan_crypto_params or NULL in case of failure 375 */ 376 struct wlan_crypto_params *wlan_crypto_peer_get_crypto_params( 377 struct wlan_objmgr_peer *peer); 378 379 /** 380 * wlan_crypto_set_peer_wep_keys - set wep keys into peer entries 381 * @vdev:vdev 382 * @peer:peer 383 * 384 * This function gets called by mlme, when auth frame is received. 385 * this helps in setting wep keys into peer data structure. 386 * 387 * Return: QDF_STATUS 388 */ 389 QDF_STATUS wlan_crypto_set_peer_wep_keys(struct wlan_objmgr_vdev *vdev, 390 struct wlan_objmgr_peer *peer); 391 392 /** 393 * wlan_crypto_register_crypto_rx_ops - set crypto_rx_ops 394 * @crypto_rx_ops: crypto_rx_ops 395 * 396 * This function gets called by object manger to register crypto rx ops. 397 * 398 * Return: QDF_STATUS 399 */ 400 QDF_STATUS wlan_crypto_register_crypto_rx_ops( 401 struct wlan_lmac_if_crypto_rx_ops *crypto_rx_ops); 402 403 /** 404 * wlan_crypto_get_crypto_rx_ops - get crypto_rx_ops from psoc 405 * @psoc: psoc 406 * 407 * This function gets called by umac to get the crypto_rx_ops 408 * 409 * Return: crypto_rx_ops 410 */ 411 struct wlan_lmac_if_crypto_rx_ops *wlan_crypto_get_crypto_rx_ops( 412 struct wlan_objmgr_psoc *psoc); 413 /** 414 * wlan_crypto_vdev_has_auth_mode - check authmode for vdev 415 * @vdev: vdev 416 * @authvalue: authvalue to be checked 417 * 418 * This function check is authvalue passed is set in vdev or not 419 * 420 * Return: true or false 421 */ 422 bool wlan_crypto_vdev_has_auth_mode(struct wlan_objmgr_vdev *vdev, 423 wlan_crypto_auth_mode authmode); 424 425 /** 426 * wlan_crypto_peer_has_auth_mode - check authmode for peer 427 * @peer: peer 428 * @authvalue: authvalue to be checked 429 * 430 * This function check is authvalue passed is set in peer or not 431 * 432 * Return: true or false 433 */ 434 bool wlan_crypto_peer_has_auth_mode(struct wlan_objmgr_peer *peer, 435 wlan_crypto_auth_mode authvalue); 436 437 /** 438 * wlan_crypto_vdev_has_ucastcipher - check ucastcipher for vdev 439 * @vdev: vdev 440 * @ucastcipher: ucastcipher to be checked 441 * 442 * This function check is ucastcipher passed is set in vdev or not 443 * 444 * Return: true or false 445 */ 446 bool wlan_crypto_vdev_has_ucastcipher(struct wlan_objmgr_vdev *vdev, 447 wlan_crypto_cipher_type ucastcipher); 448 449 /** 450 * wlan_crypto_peer_has_ucastcipher - check ucastcipher for peer 451 * @peer: peer 452 * @ucastcipher: ucastcipher to be checked 453 * 454 * This function check is ucastcipher passed is set in peer or not 455 * 456 * Return: true or false 457 */ 458 bool wlan_crypto_peer_has_ucastcipher(struct wlan_objmgr_peer *peer, 459 wlan_crypto_cipher_type ucastcipher); 460 461 462 /** 463 * wlan_crypto_vdev_has_mcastcipher - check mcastcipher for vdev 464 * @vdev: vdev 465 * @mcastcipher: mcastcipher to be checked 466 * 467 * This function check is mcastcipher passed is set in vdev or not 468 * 469 * Return: true or false 470 */ 471 bool wlan_crypto_vdev_has_mcastcipher(struct wlan_objmgr_vdev *vdev, 472 wlan_crypto_cipher_type mcastcipher); 473 474 /** 475 * wlan_crypto_peer_has_mcastcipher - check mcastcipher for peer 476 * @peer: peer 477 * @mcastcipher: mcastcipher to be checked 478 * 479 * This function check is mcastcipher passed is set in peer or not 480 * 481 * Return: true or false 482 */ 483 bool wlan_crypto_peer_has_mcastcipher(struct wlan_objmgr_peer *peer, 484 wlan_crypto_cipher_type mcastcipher); 485 486 /** 487 * wlan_crypto_get_keytype - get keytype 488 * @key: key 489 * 490 * This function gets keytype from key 491 * 492 * Return: keytype 493 */ 494 wlan_crypto_cipher_type wlan_crypto_get_key_type( 495 struct wlan_crypto_key *key); 496 497 /** 498 * wlan_crypto_vdev_getkey - get key from vdev 499 * @vdev: vdev 500 * @keyix: keyix 501 * 502 * This function gets key from vdev 503 * 504 * Return: key or NULL 505 */ 506 struct wlan_crypto_key *wlan_crypto_vdev_getkey(struct wlan_objmgr_vdev *vdev, 507 uint16_t keyix); 508 /** 509 * wlan_crypto_peer_getkey - get key from peer 510 * @peer: peer 511 * @keyix: keyix 512 * 513 * This function gets key from peer 514 * 515 * Return: key or NULL 516 */ 517 struct wlan_crypto_key *wlan_crypto_peer_getkey(struct wlan_objmgr_peer *peer, 518 uint16_t keyix); 519 /** 520 * wlan_crypto_get_peer_fils_aead - Get peer fils aead set flag 521 * @peer: Peer object 522 * 523 * This function returns the peer fils aead set flag value. 524 * 525 * Return: 1 for enabled, 0 for disabled 526 */ 527 uint8_t wlan_crypto_get_peer_fils_aead(struct wlan_objmgr_peer *peer); 528 529 /** 530 * wlan_crypto_set_peer_fils_aead - Set peer fils aead set flag 531 * @peer: Peer object 532 * @value: Value to set the flag 533 * 534 * This function set the peer fils aead set flag once FILS AUTH received. 535 * 536 * Return: None 537 */ 538 void wlan_crypto_set_peer_fils_aead( 539 struct wlan_objmgr_peer *peer, uint8_t value); 540 541 /** 542 * wlan_crypto_get_key_header - get header length 543 * @key: key 544 * 545 * This function gets header length based on keytype 546 * 547 * Return: header length 548 */ 549 uint8_t wlan_crypto_get_key_header(struct wlan_crypto_key *key); 550 551 /** 552 * wlan_crypto_get_key_trailer - get cipher trailer length 553 * @key: key 554 * 555 * This function gets cipher trailer length based on keytype 556 * 557 * Return: cipher trailer length 558 */ 559 uint8_t wlan_crypto_get_key_trailer(struct wlan_crypto_key *key); 560 561 /** 562 * wlan_crypto_get_key_miclen - get cipher miclen length 563 * @key: key 564 * 565 * This function gets cipher miclen length based on keytype 566 * 567 * Return: cipher miclen length 568 */ 569 uint8_t wlan_crypto_get_key_miclen(struct wlan_crypto_key *key); 570 571 /** 572 * wlan_crypto_get_keyid - get keyid from frame 573 * @data: frame 574 * @hdrlen: 802.11 header length 575 * 576 * This function parse frame and returns keyid 577 * 578 * Return: keyid 579 */ 580 uint16_t wlan_crypto_get_keyid(uint8_t *data, int hdrlen); 581 582 /** 583 * wlan_crypto_restore_keys - restore crypto keys in hw keycache 584 * @vdev: vdev 585 * 586 * This function restores keys in hw keycache 587 * 588 * Return: void 589 */ 590 void wlan_crypto_restore_keys(struct wlan_objmgr_vdev *vdev); 591 #endif /* end of _WLAN_CRYPTO_GLOBAL_API_H_ */ 592