1 /** 2 **************************************************************************************** 3 * 4 * @file bass.h 5 * 6 * @brief Header file - Battery Service Server Role 7 * 8 * Copyright (C) RivieraWaves 2009-2016 9 * 10 * 11 **************************************************************************************** 12 */ 13 14 #ifndef _BASS_H_ 15 #define _BASS_H_ 16 17 /** 18 **************************************************************************************** 19 * @addtogroup BAPS Battery 'Profile' Server 20 * @ingroup BAP 21 * @brief Battery 'Profile' Server 22 * @{ 23 **************************************************************************************** 24 */ 25 26 /* 27 * INCLUDE FILES 28 **************************************************************************************** 29 */ 30 #include "rwip_config.h" 31 32 #if (BLE_BATT_SERVER) 33 34 #include "bass_task.h" 35 #include "prf_types.h" 36 #include "prf.h" 37 38 /* 39 * DEFINES 40 **************************************************************************************** 41 */ 42 43 ///Maximum number of Battery Server task instances 44 #define BASS_IDX_MAX 0x01 45 46 #define BAS_CFG_FLAG_MANDATORY_MASK (0x07) 47 #define BAS_CFG_FLAG_NTF_SUP_MASK (0x08) 48 #define BAS_CFG_FLAG_MTP_BAS_MASK (0x10) 49 50 #define BASS_FLAG_NTF_CFG_BIT (0x02) 51 52 /* 53 * ENUMERATIONS 54 **************************************************************************************** 55 */ 56 57 /// Possible states of the BASS task 58 enum bass_state 59 { 60 /// Idle state 61 BASS_IDLE, 62 /// busy state 63 BASS_BUSY, 64 /// Number of defined states. 65 BASS_STATE_MAX 66 }; 67 68 /// Battery Service Attributes Indexes 69 enum 70 { 71 BAS_IDX_SVC, 72 73 BAS_IDX_BATT_LVL_CHAR, 74 BAS_IDX_BATT_LVL_VAL, 75 BAS_IDX_BATT_LVL_NTF_CFG, 76 BAS_IDX_BATT_LVL_PRES_FMT, 77 78 BAS_IDX_NB, 79 }; 80 81 /* 82 * TYPE DEFINITIONS 83 **************************************************************************************** 84 */ 85 86 /// Battery 'Profile' Server environment variable 87 struct bass_env_tag 88 { 89 /// profile environment 90 prf_env_t prf_env; 91 /// Battery Level Characteristic Presentation Format - Should not change during connection 92 struct prf_char_pres_fmt batt_level_pres_format[BASS_NB_BAS_INSTANCES_MAX]; 93 /// On-going operation 94 struct ke_msg * operation; 95 /// BAS Services Start Handle 96 uint16_t start_hdl; 97 /// Level of the battery 98 uint8_t batt_lvl[BASS_NB_BAS_INSTANCES_MAX]; 99 /// BASS task state 100 ke_state_t state[BASS_IDX_MAX]; 101 /// Notification configuration of peer devices. 102 uint8_t ntf_cfg[BLE_CONNECTION_MAX]; 103 /// Database features 104 uint8_t features; 105 /// Number of BAS 106 uint8_t svc_nb; 107 /// Cursor on connection used to notify peer devices when battery level changes 108 uint8_t cursor; 109 }; 110 111 /* 112 * GLOBAL VARIABLE DECLARATIONS 113 **************************************************************************************** 114 */ 115 116 117 /* 118 * FUNCTION DECLARATIONS 119 **************************************************************************************** 120 */ 121 122 /** 123 **************************************************************************************** 124 * @brief Retrieve BAS service profile interface 125 * 126 * @return BAS service profile interface 127 **************************************************************************************** 128 */ 129 const struct prf_task_cbs* bass_prf_itf_get(void); 130 131 /** 132 **************************************************************************************** 133 * @brief Retrieve Attribute handle from service and attribute index 134 * 135 * @param[in] svc_idx BAS Service index 136 * @param[in] att_idx Attribute index 137 * 138 * @return BAS attribute handle or INVALID HANDLE if nothing found 139 **************************************************************************************** 140 */ 141 uint16_t bass_get_att_handle(uint8_t svc_idx, uint8_t att_idx); 142 143 /** 144 **************************************************************************************** 145 * @brief Retrieve Service and attribute index form attribute handle 146 * 147 * @param[out] handle Attribute handle 148 * @param[out] svc_idx BAS Service index 149 * @param[out] att_idx Attribute index 150 * 151 * @return Success if attribute and service index found, else Application error 152 **************************************************************************************** 153 */ 154 uint8_t bass_get_att_idx(uint16_t handle, uint8_t *svc_idx, uint8_t *att_idx); 155 156 /** 157 **************************************************************************************** 158 * @brief This function fully manage notification of battery level to peer(s) device(s) 159 * according to on-going operation requested by application: 160 * - Modification of Battery Level 161 * - Indicate to a known device that battery level has change 162 **************************************************************************************** 163 */ 164 void bass_exe_operation(void); 165 166 /* 167 * TASK DESCRIPTOR DECLARATIONS 168 **************************************************************************************** 169 */ 170 171 extern const struct ke_state_handler bass_default_handler; 172 173 174 #endif /* #if (BLE_BATT_SERVER) */ 175 176 /// @} BASS 177 178 #endif /* _BASS_H_ */ 179