/* ========================================================================= * BLX Portability Library Software and documentation * (hereinafter, "Software") is an Unsupported proprietary work of * BLX, Inc. unless otherwise expressly agreed to in writing * between BLX and you. * * The Software IS NOT an item of Licensed Software or Licensed Product * under any End User Software License Agreement or Agreement for * Licensed Product with BLX or any supplement thereto. You are * permitted to use and redistribute this Software in source and binary * forms, with or without modification, provided that redistributions * of source code must retain this notice. You may not view, use, * disclose, copy or distribute this file or any information contained * herein except pursuant to this license grant from BLX. If you * do not agree with this notice, including the disclaimer below, then * you are not authorized to use the Software. * * THIS SOFTWARE IS BEING DISTRIBUTED BY BLX SOLELY ON AN "AS IS" * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL * BLX BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * ========================================================================= */ #ifndef _GSC3280_CC_H_ #define _GSC3280_CC_H_ #ifdef __cplusplus extern "C" { #endif /** @file * * This file defines the Context Context library. * * The main data structure is gsc3280_cc_if_t which is returned by either the * gsc3280_cc_if_alloc function or returned by the module to the user via a provided * function. The data structure is opaque and should only be manipulated via the * functions provied in this API. * * It manages a list of connection contexts and operations can be performed to * add, remove, query, search, and change, those contexts. Additionally, * a gsc3280_notifier_t object can be requested from the manager so that * the user can be notified whenever the context list has changed. */ #include "gsc3280_os.h" #include "gsc3280_list.h" #include "gsc3280_notifier.h" /* Notifications */ #define GSC3280_CC_LIST_CHANGED_NOTIFICATION "GSC3280_CC_LIST_CHANGED_NOTIFICATION" struct gsc3280_cc_if; typedef struct gsc3280_cc_if gsc3280_cc_if_t; /** @name Connection Context Operations */ /** @{ */ /** This function allocates memory for a gsc3280_cc_if_t structure, initializes * fields to default values, and returns a pointer to the structure or NULL on * error. */ extern gsc3280_cc_if_t *gsc3280_cc_if_alloc(void *mem_ctx, void *mtx_ctx, gsc3280_notifier_t *notifier, unsigned is_host); /** Frees the memory for the specified CC structure allocated from * gsc3280_cc_if_alloc(). */ extern void gsc3280_cc_if_free(void *mem_ctx, void *mtx_ctx, gsc3280_cc_if_t *cc_if); /** Removes all contexts from the connection context list */ extern void gsc3280_cc_clear(void *mem_ctx, gsc3280_cc_if_t *cc_if); /** Adds a connection context (CHID, CK, CDID, Name) to the connection context list. * If a CHID already exists, the CK and name are overwritten. Statistics are * not overwritten. * * @param cc_if The cc_if structure. * @param chid A pointer to the 16-byte CHID. This value will be copied. * @param ck A pointer to the 16-byte CK. This value will be copied. * @param cdid A pointer to the 16-byte CDID. This value will be copied. * @param name An optional host friendly name as defined in the association model * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name. * @param length The length othe unicode string. * @return A unique identifier used to refer to this context that is valid for * as long as this context is still in the list. */ extern int32_t gsc3280_cc_add(void *mem_ctx, gsc3280_cc_if_t *cc_if, uint8_t *chid, uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length); /** Changes the CHID, CK, CDID, or Name values of a connection context in the * list, preserving any accumulated statistics. This would typically be called * if the host decideds to change the context with a SET_CONNECTION request. * * @param cc_if The cc_if structure. * @param id The identifier of the connection context. * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL * indicates no change. * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL * indicates no change. * @param ck A pointer to the 16-byte CK. This value will be copied. NULL * indicates no change. * @param name Host friendly name UTF16-LE. NULL indicates no change. * @param length Length of name. */ extern void gsc3280_cc_change(void *mem_ctx, gsc3280_cc_if_t *cc_if, int32_t id, uint8_t *chid, uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length); /** Remove the specified connection context. * @param cc_if The cc_if structure. * @param id The identifier of the connection context to remove. */ extern void gsc3280_cc_remove(void *mem_ctx, gsc3280_cc_if_t *cc_if, int32_t id); /** Get a binary block of data for the connection context list and attributes. * This data can be used by the OS specific driver to save the connection * context list into non-volatile memory. * * @param cc_if The cc_if structure. * @param length Return the length of the data buffer. * @return A pointer to the data buffer. The memory for this buffer should be * freed with GSC3280_FREE() after use. */ extern uint8_t *gsc3280_cc_data_for_save(void *mem_ctx, gsc3280_cc_if_t *cc_if, unsigned int *length); /** Restore the connection context list from the binary data that was previously * returned from a call to gsc3280_cc_data_for_save. This can be used by the OS specific * driver to load a connection context list from non-volatile memory. * * @param cc_if The cc_if structure. * @param data The data bytes as returned from gsc3280_cc_data_for_save. * @param length The length of the data. */ extern void gsc3280_cc_restore_from_data(void *mem_ctx, gsc3280_cc_if_t *cc_if, uint8_t *data, unsigned int length); /** Find the connection context from the specified CHID. * * @param cc_if The cc_if structure. * @param chid A pointer to the CHID data. * @return A non-zero identifier of the connection context if the CHID matches. * Otherwise returns 0. */ extern uint32_t gsc3280_cc_match_chid(gsc3280_cc_if_t *cc_if, uint8_t *chid); /** Find the connection context from the specified CDID. * * @param cc_if The cc_if structure. * @param cdid A pointer to the CDID data. * @return A non-zero identifier of the connection context if the CHID matches. * Otherwise returns 0. */ extern uint32_t gsc3280_cc_match_cdid(gsc3280_cc_if_t *cc_if, uint8_t *cdid); /** Retrieve the CK from the specified connection context. * * @param cc_if The cc_if structure. * @param id The identifier of the connection context. * @return A pointer to the CK data. The memory does not need to be freed. */ extern uint8_t *gsc3280_cc_ck(gsc3280_cc_if_t *cc_if, int32_t id); /** Retrieve the CHID from the specified connection context. * * @param cc_if The cc_if structure. * @param id The identifier of the connection context. * @return A pointer to the CHID data. The memory does not need to be freed. */ extern uint8_t *gsc3280_cc_chid(gsc3280_cc_if_t *cc_if, int32_t id); /** Retrieve the CDID from the specified connection context. * * @param cc_if The cc_if structure. * @param id The identifier of the connection context. * @return A pointer to the CDID data. The memory does not need to be freed. */ extern uint8_t *gsc3280_cc_cdid(gsc3280_cc_if_t *cc_if, int32_t id); extern uint8_t *gsc3280_cc_name(gsc3280_cc_if_t *cc_if, int32_t id, uint8_t *length); /** Checks a buffer for non-zero. * @param id A pointer to a 16 byte buffer. * @return true if the 16 byte value is non-zero. */ static inline unsigned gsc3280_assoc_is_not_zero_id(uint8_t *id) { int i; for (i=0; i<16; i++) { if (id[i]) return 1; } return 0; } /** Checks a buffer for zero. * @param id A pointer to a 16 byte buffer. * @return true if the 16 byte value is zero. */ static inline unsigned gsc3280_assoc_is_zero_id(uint8_t *id) { return !gsc3280_assoc_is_not_zero_id(id); } /** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into * buffer. */ static inline int gsc3280_print_id_string(char *buffer, uint8_t *id) { char *ptr = buffer; int i; for (i=0; i<16; i++) { ptr += GSC3280_SPRINTF(ptr, "%02x", id[i]); if (i < 15) { ptr += GSC3280_SPRINTF(ptr, " "); } } return ptr - buffer; } /** @} */ #ifdef __cplusplus } #endif #endif /* _GSC3280_CC_H_ */