| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2012, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bsettop_amessage.h $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * Message filtering and raw ATM packet capture api. |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | * |
|---|
| 21 | ***************************************************************************/ |
|---|
| 22 | |
|---|
| 23 | #ifndef __BSETTOP_AMESSAGE_H__ |
|---|
| 24 | #define __BSETTOP_AMESSAGE_H__ |
|---|
| 25 | |
|---|
| 26 | #include "bsettop_types.h" |
|---|
| 27 | |
|---|
| 28 | /** \file bsettop_amessage.h |
|---|
| 29 | This file defines interfaces for PSI section filtering. Main difference between |
|---|
| 30 | this one and smessage is that is the message comes from SCTE 55-2 (ATM cell). |
|---|
| 31 | The DTA PSI filtering works differently than the hardware PSI filtering |
|---|
| 32 | in settop api and nexus. The DTA PSI filters are combination of the software |
|---|
| 33 | filtering with the hardware assist. For performance and efficiency reasons |
|---|
| 34 | the sections are filtered in to the application supplied buffer instead of per |
|---|
| 35 | filter circular buffer as it happens with the hardware implementation. This |
|---|
| 36 | allows application to immediately start processing the data and avoid an |
|---|
| 37 | extra copying operation. |
|---|
| 38 | The caller allocates a buffer, capable of containing maximum expected |
|---|
| 39 | section size. If the caller does not know expected section size, buffer size |
|---|
| 40 | should be 1K for standard sections and 4 K for private sections. |
|---|
| 41 | The caller then would initialize the section filtering api, fill the parameter |
|---|
| 42 | structure and start the section filtering. |
|---|
| 43 | When any of the filters match a section, the section filtering api will copy |
|---|
| 44 | this section in to the caller supplied buffer and if required would verify the |
|---|
| 45 | CRC. When the section is completely received and the CRC is verified, the |
|---|
| 46 | section filtering code will invoke the caller supplied callback. In the |
|---|
| 47 | callback the caller can process section data and chose to continue filtering |
|---|
| 48 | or choose to stop filtering sections. |
|---|
| 49 | */ |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | Message stream handle. |
|---|
| 53 | This handle is returned by the open call and used in all subsequent |
|---|
| 54 | calls to control the psi interface functionality. |
|---|
| 55 | */ |
|---|
| 56 | typedef struct amessage_stream * amessage_stream_t; |
|---|
| 57 | |
|---|
| 58 | /** \struct amessage_filter |
|---|
| 59 | Structure that is used to specify a PSI filter. |
|---|
| 60 | |
|---|
| 61 | All filtering is done using bit by bit comparisons. |
|---|
| 62 | There are two types of masks that are used in conjunction with the coefficient. |
|---|
| 63 | inclusion mask (mask) - for all inclusion mask bits that are unmasked |
|---|
| 64 | (set to 0) ALL of the corresponding bits in the |
|---|
| 65 | message must match the bits specified by the coef in order to |
|---|
| 66 | be included. If one bit differs, it will be excluded. |
|---|
| 67 | |
|---|
| 68 | exclusion mask (excl) - for all exclusion mask bits that are unmasked |
|---|
| 69 | (set to 0) at least one of the corresponding bits |
|---|
| 70 | in the message must NOT match the bits specified |
|---|
| 71 | by the coef in order to be included. If all of the bits |
|---|
| 72 | match, it will be excluded. |
|---|
| 73 | Results from both comparisons are AND'd together to form the final pass/fail decision. |
|---|
| 74 | Exception: Currently for MPEG2 streams, byte 2 (i.e. the message length field) |
|---|
| 75 | of the filter and the MPEG2 message data is ignored. |
|---|
| 76 | */ |
|---|
| 77 | /** \var amessage_filter::mask |
|---|
| 78 | Any bit of the mask that is set to 0 will allow the corresponding bit of the |
|---|
| 79 | coefficient to be compared against the PSI message data. |
|---|
| 80 | */ |
|---|
| 81 | /** \var amessage_filter::coef |
|---|
| 82 | Coefficient bits to be compared against the PSI message data. |
|---|
| 83 | */ |
|---|
| 84 | /** \var amessage_filter::excl |
|---|
| 85 | Any bit of the exclusion that is set to 0 will allow the corresponding bit |
|---|
| 86 | of the coefficient to be compared against the PSI message data. |
|---|
| 87 | */ |
|---|
| 88 | typedef struct amessage_filter { |
|---|
| 89 | uint8_t mask[16]; |
|---|
| 90 | uint8_t coef[16]; |
|---|
| 91 | uint8_t excl[16]; |
|---|
| 92 | } amessage_filter; |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | Section callback type. |
|---|
| 96 | |
|---|
| 97 | The caller must provide a function of this type to be called when the section |
|---|
| 98 | is captured by the section filters. This is the only way for a caller to obtain |
|---|
| 99 | the section. |
|---|
| 100 | After this call is called sections are longer will be captured by this filter |
|---|
| 101 | unless the callback returns non NULL pointer. User must stop and restart |
|---|
| 102 | the filter to resume the section capture. |
|---|
| 103 | |
|---|
| 104 | \warning User can not call any amessage_* api from this callback such call |
|---|
| 105 | will result in a deadlock. |
|---|
| 106 | |
|---|
| 107 | This callback is called directly from the filter task and it |
|---|
| 108 | must return fast. Delaying return from the callback will adversely impact |
|---|
| 109 | the message filter performance and may result in overflow for all the other |
|---|
| 110 | filters. If caller has to do substantial work he must convey the information |
|---|
| 111 | to another task and do the work in another context. If NULL is returned by |
|---|
| 112 | the callback message filtering will stop for this filter. If non NULL pointer |
|---|
| 113 | is returned filtering will continue in to the buffer pointed by this pointer. |
|---|
| 114 | |
|---|
| 115 | @param context - user context provided when message capture was started. |
|---|
| 116 | @param data_size - size of message captured in the provided buffer. |
|---|
| 117 | @return |
|---|
| 118 | New buffer pointer to use for the next section capture or NULL if no more |
|---|
| 119 | sections should be captured and operation of the filter should be suspended. |
|---|
| 120 | If the filter should continue to capture sections in to the old buffer, the |
|---|
| 121 | callback should return the same pointer that was originally passed to the |
|---|
| 122 | start function. Size of the new buffer must be the same or larger than the |
|---|
| 123 | size of the buffer passed in to the amessage_start function. |
|---|
| 124 | |
|---|
| 125 | @see amessage_stream_params_t |
|---|
| 126 | */ |
|---|
| 127 | typedef void * (*amessage_callback)(void * context, size_t data_size); |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | Parameters for the amessage_start function. |
|---|
| 131 | |
|---|
| 132 | Structure for providing parameters to the amessage_start function. |
|---|
| 133 | |
|---|
| 134 | @param band - parser band |
|---|
| 135 | @param vpi - vpi for ATM packet filter |
|---|
| 136 | @param vci - vci for ATM packet filter |
|---|
| 137 | @param filter - message filter |
|---|
| 138 | @param buffer - buffer for complete message |
|---|
| 139 | @param buffer_size - size of the buffer |
|---|
| 140 | @param hec_disabled - disable ATM HEC checking, HEC checking enabled by default. |
|---|
| 141 | @param data_ready_callback - notification callback invoked when message is captured. |
|---|
| 142 | @param overflow - notification callback invoked when overflow happens. |
|---|
| 143 | |
|---|
| 144 | Only following parameters are used when stream is captured in to circular |
|---|
| 145 | buffer - band, vpi, vci, buffer_size, hec_disabled. All other parameters are ignored. |
|---|
| 146 | |
|---|
| 147 | @see amessage_stream_params_init, amessage_start |
|---|
| 148 | */ |
|---|
| 149 | typedef struct amessage_stream_params_tag { |
|---|
| 150 | bband_t band; |
|---|
| 151 | uint8_t vpi; |
|---|
| 152 | uint16_t vci; |
|---|
| 153 | amessage_filter filter; |
|---|
| 154 | void * buffer; |
|---|
| 155 | size_t buffer_size; |
|---|
| 156 | bool hec_disabled; |
|---|
| 157 | amessage_callback data_ready_callback; |
|---|
| 158 | amessage_callback overflow; |
|---|
| 159 | void * callback_context; |
|---|
| 160 | void * priv; |
|---|
| 161 | } amessage_stream_params_t; |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | Initialize the message subsystem. |
|---|
| 165 | No other functions can be called before this function is called or results |
|---|
| 166 | of other function calls are undefined. |
|---|
| 167 | |
|---|
| 168 | @return b_ok if success, error code otherwise. |
|---|
| 169 | */ |
|---|
| 170 | bresult amessage_init(void); |
|---|
| 171 | |
|---|
| 172 | /** |
|---|
| 173 | Initialize parameters with default values. |
|---|
| 174 | |
|---|
| 175 | This function will fill the given structure with the default values that are |
|---|
| 176 | appropriate for the message stream type. This function must be called before |
|---|
| 177 | setting up the parameter structure for the amessage_open call. |
|---|
| 178 | |
|---|
| 179 | @param params - parameter structure to fill with the default values. |
|---|
| 180 | @param stream - stream for which to fill the structure. |
|---|
| 181 | |
|---|
| 182 | @see amessage_open |
|---|
| 183 | */ |
|---|
| 184 | void amessage_stream_params_init( amessage_stream_params_t *params, amessage_stream_t stream); |
|---|
| 185 | |
|---|
| 186 | /** |
|---|
| 187 | Open message with the desired format. |
|---|
| 188 | |
|---|
| 189 | This call returns the message handle which is obtained from the internal list. |
|---|
| 190 | Be sure to call amessage_close after the handle is no longer needed. Failing |
|---|
| 191 | to do so will result in memory leak and running out of handles. |
|---|
| 192 | |
|---|
| 193 | @param format - desired format for the message capture. |
|---|
| 194 | @return amessage_stream_t handle or NULL if the call fails. |
|---|
| 195 | |
|---|
| 196 | @see amessage_close |
|---|
| 197 | */ |
|---|
| 198 | amessage_stream_t amessage_open(void); |
|---|
| 199 | |
|---|
| 200 | /** |
|---|
| 201 | Start message capture. |
|---|
| 202 | |
|---|
| 203 | This call will start message filtering. When message is captured it will be |
|---|
| 204 | copied in to the provided buffer and callback will be called. After message is |
|---|
| 205 | captured this filter will be disabled if NULL is returned by callback. If |
|---|
| 206 | caller desires to continue message filtering, callback should return a pointer |
|---|
| 207 | to the buffer in which to capture next message. |
|---|
| 208 | If message callback returns NULL and user wants to resume filtering, message |
|---|
| 209 | filter should be stopped and restarted with new parameters by calling this |
|---|
| 210 | api again. |
|---|
| 211 | This call will start capture and immediately return. |
|---|
| 212 | |
|---|
| 213 | @param params - parameters for message capture |
|---|
| 214 | @param stream - stream handle for which to start capture. |
|---|
| 215 | |
|---|
| 216 | @return b_ok if capture was started, error code otherwise. |
|---|
| 217 | |
|---|
| 218 | @see amessage_stop, amessage_stream_params_init |
|---|
| 219 | */ |
|---|
| 220 | bresult amessage_start(const amessage_stream_params_t * params, amessage_stream_t stream); |
|---|
| 221 | |
|---|
| 222 | /** |
|---|
| 223 | Stop message capture. |
|---|
| 224 | Stop capture and if possible free internal hardware and software |
|---|
| 225 | resources. |
|---|
| 226 | |
|---|
| 227 | @param stream - stream for which to stop message capture. |
|---|
| 228 | |
|---|
| 229 | @return b_ok if capture was stopped, error code otherwise. |
|---|
| 230 | |
|---|
| 231 | @see amessage_stop |
|---|
| 232 | */ |
|---|
| 233 | bresult amessage_stop(amessage_stream_t stream); |
|---|
| 234 | |
|---|
| 235 | /** |
|---|
| 236 | Close message capture for given stream. |
|---|
| 237 | |
|---|
| 238 | Close message capture for given stream and return stream to the list of free |
|---|
| 239 | streams. User must call amessage_stop before calling this api and user must |
|---|
| 240 | call this api if he no longer needs stream handle. If this api is not called |
|---|
| 241 | stream handle will be leaked and eventually system will run out of stream |
|---|
| 242 | handles as they are limited. |
|---|
| 243 | |
|---|
| 244 | @param stream - stream handle to free. |
|---|
| 245 | |
|---|
| 246 | @see amessage_open |
|---|
| 247 | */ |
|---|
| 248 | void amessage_close(amessage_stream_t stream); |
|---|
| 249 | |
|---|
| 250 | /** |
|---|
| 251 | Get circular buffer pointer for the stream capture buffer. |
|---|
| 252 | Get the pointer to the start of unread data in the circular buffer. This call |
|---|
| 253 | is valid only for some types of message capture and using it for any other |
|---|
| 254 | type will result in error. |
|---|
| 255 | |
|---|
| 256 | @param stream - desired stream handle |
|---|
| 257 | @param pbuffer - pointer to the pointer to buffer. After the function returns |
|---|
| 258 | this variable will contain the pointer to the start of the available data. |
|---|
| 259 | @param plength - pointer to the length of the data. After function returns this |
|---|
| 260 | variable will contain length of the valid data in the buffer. |
|---|
| 261 | |
|---|
| 262 | @return b_ok if call was successful error otherwise. If error is returned |
|---|
| 263 | values of *pbuffer and *plength are not defined and should be discarded. |
|---|
| 264 | |
|---|
| 265 | @see amessage_read_complete, amessage_start |
|---|
| 266 | */ |
|---|
| 267 | bresult amessage_get_buffer(amessage_stream_t stream, const void ** pbuffer, size_t * plength); |
|---|
| 268 | |
|---|
| 269 | /** |
|---|
| 270 | Notify circular buffer about amount of consumed data. |
|---|
| 271 | |
|---|
| 272 | Notify the circular buffer about amount of the consumed data and advance the |
|---|
| 273 | read pointer. This call is valid only for some types of the message capture |
|---|
| 274 | and using it for any other type will result in error. Attempt to consume more |
|---|
| 275 | data that is available in the circular buffer will result in error. |
|---|
| 276 | |
|---|
| 277 | @param stream - desired stream handle |
|---|
| 278 | @param consumed - amount of data that was consumed. Read pointer will be advanced by |
|---|
| 279 | that amount. |
|---|
| 280 | |
|---|
| 281 | @return b_ok if call was successful error otherwise. |
|---|
| 282 | |
|---|
| 283 | @see amessage_get_buffer, amessage_start |
|---|
| 284 | */ |
|---|
| 285 | bresult amessage_read_complete(amessage_stream_t stream, size_t consumed); |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | #endif /*__BSETTOP_AMESSAGE_H__*/ |
|---|