1 /* 2 * Copyright 2018 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _SCRAMBLER_H_ 10 #define _SCRAMBLER_H_ 11 12 /*! 13 * @addtogroup Scrambler 14 * @{ 15 */ 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 21 /*! @brief scrambler_whiten_poly_type bit definitions. */ 22 typedef enum _scrambler_whiten_poly_type 23 { 24 kSCRAMBLER_GaloisPolyType = 0U, /*!< A Galois type LFSR is used with the whiten polynomial. */ 25 kSCRAMBLER_FibonnaciPolyType = 1U /*!< A Fibonacci type LFSR is used with the whiten polynomial. */ 26 } scrambler_whiten_poly_type_t; 27 28 /*! 29 * @brief whitenRefIn bit definitions. 30 * 31 * @note The input data stream is reflected bit-wise, per byte. Bit 7 becomes bit 0, bit 6 becomes bit 1, etc. 32 * Will only cause the reflection of the payload data bits as they are used in the whiten calculation 33 * and will not cause any change in the output bit order. 34 */ 35 typedef enum _scrambler_whiten_cfg_ref_in 36 { 37 kSCRAMBLER_WhitenInputNoRef = 0U, /*!< Do not manipulate input data stream. */ 38 kSCRAMBLER_WhitenRefInput = 1U /*!< Reflect each byte in the input stream bitwise. */ 39 } scrambler_whiten_cfg_ref_in_t; 40 41 /*! * @brief Whitener module configure structure. */ 42 typedef struct _whitener_config 43 { 44 scrambler_whiten_poly_type_t type; /*!< Whiten polynomial type. See "scrambler_whiten_poly_type_t". */ 45 scrambler_whiten_cfg_ref_in_t whitenRefIn; /*!< Whiten reflect input. See "scrambler_whiten_cfg_ref_in_t". */ 46 uint16_t whitenInitValue; /*!< Initialization value for Whitening/De-whitening. Maximum 9 bits. */ 47 uint16_t whitenPolyValue; /*!< Whitener polynomial vaule. The polynomial value must be right-justified 48 if smaller than 9-bits. Maximum 9 bits. */ 49 uint8_t whitenSize; /*!< Length of whitener LFSR. Maximum value 9. */ 50 } whitener_config_t; 51 52 /******************************************************************************* 53 * API 54 ******************************************************************************/ 55 56 #if defined(__cplusplus) 57 extern "C" { 58 #endif 59 60 /*! 61 * @brief Software whitening function. 62 * 63 * The function whitens/de-whitens the input buffer. 64 * 65 * @note This function will store the result in the input buffer. 66 * @code 67 * config = (whitener_config_t) { 68 * .type = kSCRAMBLER_GaloisPolyType, 69 * .whitenRefIn = kSCRAMBLER_WhitenInputNoRef, 70 * .whitenSize = 8, 71 * .whitenInit = 0x1f, 72 * .whitenPoly = 0x0, 73 * }; 74 * 75 * SCRAMBLER_Whiten(&config, p, SCRAMBLER_BUF_SZ); 76 * 77 * @endcode 78 * @param whitenerConfig whitener configuration structure pointer. See "whitener_config_t". 79 * @param pBuff Input buffer pointer and store the result in the input buffer. 80 * @param buffLength buffer length. 81 */ 82 void SCRAMBLER_Whiten(whitener_config_t *whitenerConfig, uint8_t *pBuff, uint32_t buffLength); 83 84 #if defined(__cplusplus) 85 } 86 #endif 87 88 /*! @} */ 89 90 #endif /* _SCRAMBLER_H_ */ 91