@@ -57,6 +57,7 @@ typedef struct
5757 uint32_t signCounter ; /* sign counter for this connection */
5858 uint8_t * pCsrk ; /* signing key for this connection */
5959 attsSignBuf_t * pBuf ; /* current data being processed */
60+ bool_t authenticated ; /* Indicate if the CSRK is authenticated or not */
6061} attsSignCcb_t ;
6162
6263/* ATTS signed PDU control block */
@@ -160,53 +161,69 @@ static void attsProcSignedWrite(attCcb_t *pCcb, uint16_t len, uint8_t *pPacket)
160161 /* find attribute */
161162 if ((pAttr = attsFindByHandle (handle , & pGroup )) != NULL )
162163 {
163- /* verify permissions */
164- if (attsPermissions ( pCcb -> connId , ATTS_PERMIT_WRITE , handle , pAttr -> permissions ) != ATT_SUCCESS )
164+ /* verify signed write is permitted */
165+ if (( pAttr -> settings & ATTS_SET_ALLOW_SIGNED ) == 0 )
165166 {
166167 return ;
167168 }
168- /* verify signed write is permitted */
169- else if ((pAttr -> settings & ATTS_SET_ALLOW_SIGNED ) == 0 )
169+
170+ /* verify that csrk is present */
171+ if (attsSignCcbByConnId (pCcb -> connId )-> pCsrk == NULL ) {
172+ return ;
173+ }
174+
175+ /* verify basic permissions */
176+ if ((pAttr -> permissions & (ATTS_PERMIT_WRITE | ATTS_PERMIT_WRITE_ENC )) == 0 )
170177 {
171178 return ;
172179 }
180+
181+ /* verify authentication */
182+ if ((pAttr -> permissions & ATTS_PERMIT_WRITE_AUTH ) &&
183+ (attsSignCcbByConnId (pCcb -> connId )-> authenticated == 0 ))
184+ {
185+ return ;
186+ }
187+
188+ /* Note: authorization not verified at this stage as it is reserved for lesc
189+ writes; authorization occurs latter when the write cb is called */
190+
173191 /* verify write length, fixed length */
174- else if (((pAttr -> settings & ATTS_SET_VARIABLE_LEN ) == 0 ) &&
192+ if (((pAttr -> settings & ATTS_SET_VARIABLE_LEN ) == 0 ) &&
175193 (writeLen != pAttr -> maxLen ))
176194 {
177195 return ;
178196 }
197+
179198 /* verify write length, variable length */
180- else if (((pAttr -> settings & ATTS_SET_VARIABLE_LEN ) != 0 ) &&
199+ if (((pAttr -> settings & ATTS_SET_VARIABLE_LEN ) != 0 ) &&
181200 (writeLen > pAttr -> maxLen ))
182201 {
183202 return ;
184203 }
185- else
204+
205+ /* allocate buffer to store packet and parameters */
206+ if ((pBuf = WsfBufAlloc (sizeof (attsSignBuf_t ) - 1 + len )) != NULL )
186207 {
187- /* allocate buffer to store packet and parameters */
188- if ((pBuf = WsfBufAlloc (sizeof (attsSignBuf_t ) - 1 + len )) != NULL )
189- {
190- /* initialize buffer */
191- pBuf -> pCcb = pCcb ;
192- pBuf -> handle = handle ;
193- pBuf -> writeLen = writeLen ;
194- pBuf -> connId = pCcb -> connId ;
195- memcpy (pBuf -> packet , (pPacket + L2C_PAYLOAD_START ), len );
208+ /* initialize buffer */
209+ pBuf -> pCcb = pCcb ;
210+ pBuf -> handle = handle ;
211+ pBuf -> writeLen = writeLen ;
212+ pBuf -> connId = pCcb -> connId ;
213+ memcpy (pBuf -> packet , (pPacket + L2C_PAYLOAD_START ), len );
196214
197- /* check if a signed write is already in progress */
198- pSignCcb = attsSignCcbByConnId (pCcb -> connId );
215+ /* check if a signed write is already in progress */
216+ pSignCcb = attsSignCcbByConnId (pCcb -> connId );
199217
200- if (pSignCcb -> pBuf != NULL )
201- {
202- /* signed write in progress; queue packet */
203- WsfQueueEnq (& attsSignCb .msgQueue , pBuf );
204- }
205- else
206- {
207- /* start signed data processing */
208- attsSignedWriteStart (pSignCcb , pBuf );
209- }
218+ if (pSignCcb -> pBuf != NULL )
219+ {
220+ /* signed write in progress; queue packet */
221+ WsfQueueEnq (& attsSignCb .msgQueue , pBuf );
222+ }
223+ else
224+ {
225+ /* start signed data processing */
226+ attsSignedWriteStart (pSignCcb , pBuf );
210227 }
211228 }
212229 }
@@ -336,13 +353,15 @@ void AttsSignInit(void)
336353 *
337354 * \param connId DM connection ID.
338355 * \param pCsrk Pointer to data signing key (CSRK).
356+ * \param authenticated True if CSRK is authenticated and false otherwise.
339357 *
340358 * \return None.
341359 */
342360/*************************************************************************************************/
343- void AttsSetCsrk (dmConnId_t connId , uint8_t * pCsrk )
361+ void AttsSetCsrk (dmConnId_t connId , uint8_t * pCsrk , bool_t authenticated )
344362{
345363 attsSignCcbByConnId (connId )-> pCsrk = pCsrk ;
364+ attsSignCcbByConnId (connId )-> authenticated = authenticated ;
346365}
347366
348367/*************************************************************************************************/
0 commit comments