1 /******************************************************************************
2 * FILE PURPOSE: Data Mode Main File
3 ******************************************************************************
4 * FILE NAME: sallddm.c
5 *
6 * DESCRIPTION: The main module for Data Mode Code
7 *
8 * (C) Copyright 2009-2014, Texas Instruments Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
20 * distribution.
21 *
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 */
39 /* RTSC header files */
41 /* Standard include files */
42 #include <string.h>
44 /* SALLD header files */
45 #include <ti/drv/sa/salld.h>
46 #include <ti/drv/sa/sa_osal.h>
47 #include "src/salldloc.h"
48 #include "src/salldport.h"
49 #include "sallddm.h"
50 #include "sallddmloc.h"
52 /* Defined for testing. Should be moved to makedefs.mk */
53 #define dmGetChID(mid_chnum) ( (((uint16_t)(mid_chnum)) & 0x00FF )-1)
55 /****************************************************************************
56 * FUNCTION PURPOSE: Data Mode Key Setup
57 ****************************************************************************
58 * DESCRIPTION: Update the Data Mode channel key information based on the input
59 * parameters.
60 *
61 * uint16_t salld_data_mode_setup_key(
62 * salldDataModeInst_t* inst -> Point to Data Mode channel instance
63 * salldDataModeComInfo_t* pComInfo -> pointer to the instance key storage
64 * Sa_DataModeKeyParams_t* pKeyParams) -> pointer to the key configuration
65 * parameters.
66 *
67 * Return values: FALSE : invalid parameters
68 * TRUE: successful updtae
69 *
70 ***************************************************************************/
71 uint16_t salld_data_mode_setup_key(salldDataModeInst_t *inst,
72 salldDataModeComInfo_t* pComInfo, Sa_DataModeKeyParams_t* pKeyParams)
73 {
74 uint16_t ctrlBitMap = pKeyParams->ctrlBitfield;
76 if(ctrlBitMap & sa_DATA_MODE_KEY_CTRL_ENC_KEY)
77 {
78 /* Copy Encryption Key */
79 memcpy(pComInfo->sessionEncKey, pKeyParams->sessionEncKey, pComInfo->config.sessionEncKeySize);
80 }
82 if( ctrlBitMap & sa_DATA_MODE_KEY_CTRL_MAC_KEY)
83 {
84 /* Copy MAC Key */
85 memcpy(pComInfo->sessionMacKey, pKeyParams->sessionAuthKey, pComInfo->config.sessionMacKeySize);
86 }
88 if( ctrlBitMap & sa_DATA_MODE_KEY_CTRL_SALT)
89 {
90 /* Copy session Salt */
91 memcpy(pComInfo->sessionSalt, pKeyParams->sessionSalt, pComInfo->config.sessionSaltSize);
92 }
94 return TRUE;
95 }
97 /****************************************************************************
98 * FUNCTION PURPOSE: Verify Data Mode Configuration Parameters
99 ****************************************************************************
100 * DESCRIPTION: Verify Data Mode general configuration parameters for consistency
101 * with the encryption and authentication mode
102 *
103 * uint16_t salld_DM_verify_config_params(
104 * Sa_CipherMode_e cipherMode, -> Ciphering mode
105 * Sa_AuthMode_e authMode, -> Aurthentication Mode
106 * Sa_DataModeConfigParams_t* pDataModeConfig) ->pointer to the IPsec configuration
107 * parameters.
108 *
109 * Return values: FALSE : invalid parameters
110 * TRUE: valid parameters
111 *
112 ***************************************************************************/
113 static uint16_t salld_dm_verify_config_params(Sa_CipherMode_e cipherMode, Sa_AuthMode_e authMode,
114 Sa_DataModeConfigParams_t* pDataModeConfig)
115 {
117 /* Common Check */
118 if((pDataModeConfig->sessionEncKeySize > 32) ||
119 #if defined (NSS_LITE2)
120 (pDataModeConfig->sessionMacKeySize > 64))
121 #else
122 (pDataModeConfig->sessionMacKeySize > 32))
123 #endif
124 return (FALSE);
126 #if defined(NSS_LITE) || defined(NSS_LITE2)
127 /* NSS LITE devices do not have Air Cipher Engines */
128 if ((pDataModeConfig->ctrlBitMap & sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG) == sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG)
129 return (FALSE);
130 #endif
132 if((authMode == sa_AuthMode_NULL) &&
133 ((cipherMode != sa_CipherMode_GCM) &&
134 (cipherMode != sa_CipherMode_CCM)))
135 {
136 if(pDataModeConfig->macSize != 0)
137 return(FALSE);
138 }
140 /* Ciphering mode specific check */
141 switch (cipherMode)
142 {
143 case sa_CipherMode_CCM:
144 if(((pDataModeConfig->ivSize + \
145 pDataModeConfig->sessionSaltSize) > 13) ||
146 (pDataModeConfig->aadSize > 14) ||
147 (authMode != sa_AuthMode_NULL))
148 return (FALSE);
149 break;
151 case sa_CipherMode_DES_CBC:
152 case sa_CipherMode_3DES_CBC:
153 if((pDataModeConfig->ivSize != 8) ||
154 (pDataModeConfig->sessionSaltSize != 0))
155 return (FALSE);
156 break;
158 case sa_CipherMode_GCM:
159 if(((pDataModeConfig->ivSize + \
160 pDataModeConfig->sessionSaltSize) != 12) ||
161 (pDataModeConfig->aadSize > 16) ||
162 (authMode != sa_AuthMode_NULL))
163 return (FALSE);
164 break;
166 #if !defined(NSS_LITE) && !defined(NSS_LITE2)
167 case sa_CipherMode_KASUMI_F8:
168 if((pDataModeConfig->ivSize != 8))
169 return (FALSE);
170 break;
172 case sa_CipherMode_SNOW3G_F8:
173 if((pDataModeConfig->ivSize != 16))
174 return (FALSE);
175 break;
177 case sa_CipherMode_AES_CTR:
178 case sa_CipherMode_AES_F8:
179 case sa_CipherMode_AES_CBC:
180 case sa_CipherMode_GSM_A53:
181 case sa_CipherMode_ECSD_A53:
182 case sa_CipherMode_GEA3:
183 case sa_CipherMode_NULL:
184 break;
186 #else
187 case sa_CipherMode_AES_CTR:
188 case sa_CipherMode_AES_F8:
189 case sa_CipherMode_AES_CBC:
190 case sa_CipherMode_NULL:
191 break;
193 #endif
195 default:
196 return (FALSE);
197 }
199 /* Encryption mode specific check */
200 switch (authMode)
201 {
202 case sa_AuthMode_GMAC:
203 if(((pDataModeConfig->ivSize + \
204 pDataModeConfig->sessionSaltSize) != 12) ||
205 (pDataModeConfig->aadSize > 16) ||
206 (cipherMode != sa_CipherMode_NULL))
207 return (FALSE);
208 break;
210 case sa_AuthMode_GMAC_AH:
211 if((pDataModeConfig->ivSize != 8) ||
212 (pDataModeConfig->sessionSaltSize != 4) ||
213 (cipherMode != sa_CipherMode_NULL))
214 return (FALSE);
215 break;
217 case sa_AuthMode_KASUMI_F9:
218 if((pDataModeConfig->ivSize != 8))
219 return (FALSE);
220 break;
222 case sa_AuthMode_MD5:
223 case sa_AuthMode_SHA1:
224 case sa_AuthMode_SHA2_224:
225 case sa_AuthMode_SHA2_256:
226 case sa_AuthMode_SHA2_384:
227 case sa_AuthMode_SHA2_512:
228 case sa_AuthMode_HMAC_MD5:
229 case sa_AuthMode_HMAC_SHA1:
230 case sa_AuthMode_HMAC_SHA2_224:
231 case sa_AuthMode_HMAC_SHA2_256:
232 case sa_AuthMode_CMAC:
233 case sa_AuthMode_CBC_MAC:
234 case sa_AuthMode_AES_XCBC:
235 case sa_AuthMode_NULL:
236 case sa_AuthMode_HMAC_SHA2_384:
237 case sa_AuthMode_HMAC_SHA2_512:
238 break;
240 default:
241 return(FALSE);
242 }
245 return TRUE;
246 }
249 /****************************************************************************
250 * FUNCTION PURPOSE: Data Mode Control
251 ****************************************************************************
252 * DESCRIPTION: Data Mode Control functions
253 *
254 * int16_t salld_data_mode_control (
255 * void *salldInst - a pointer to SALLD channel instance
256 * void *ctrl) - a pointer to control structure
257 *
258 * Return values: sa_ERR_OK
259 * sa_ERR_GEN
260 * sa_ERR_PARAMS
261 *
262 ***************************************************************************/
263 int16_t salld_data_mode_control (void *salldInst, void *salldCtrl)
264 {
265 salldDataModeInst_t *inst = (salldDataModeInst_t *)salldInst;
266 salldDataModeTxInst_t *txInst = &inst->txInst;
267 Sa_ChanCtrlInfo_t *ctrl = (Sa_ChanCtrlInfo_t *)salldCtrl;
268 uint16_t bitmap;
269 int16_t ret;
271 switch(ctrl->ctrlType)
272 {
273 /* SALLD cipher, mac and key size selection */
274 case sa_CHAN_CTRL_GEN_CONFIG:
275 {
276 bitmap = ctrl->ctrlInfo.gen.validBitfield;
277 if( bitmap & sa_CONTROLINFO_VALID_TX_CTRL)
278 {
279 /* Input parameters check */
280 Sa_GenConfigParams_t* pGenConfig = &ctrl->ctrlInfo.gen.txCtrl;
281 Sa_DataModeConfigParams_t* pDataModeConfig = &ctrl->ctrlInfo.gen.txCtrl.params.data;
283 if (salld_dm_verify_config_params(pGenConfig->cipherMode, pGenConfig->authMode, pDataModeConfig))
284 {
285 txInst->cipherMode = pGenConfig->cipherMode;
286 txInst->authMode = pGenConfig->authMode;
287 txInst->destInfo = pGenConfig->destInfo;
288 txInst->comInfo.config = *pDataModeConfig;
289 if(txInst->cipherMode == sa_CipherMode_NULL)
290 txInst->comInfo.config.enc1st = FALSE;
291 }
292 else
293 {
294 return(sa_ERR_PARAMS);
295 }
296 }
298 /*
299 * Is it time to form and register security context?
300 */
301 if(!SALLD_TEST_STATE_TX_SC_VALID(&inst->salldInst) &&
302 SALLD_TEST_STATE_TX_ON(&inst->salldInst))
303 {
304 if ((ret = salld_data_mode_set_sc(inst)) != sa_ERR_OK)
305 {
306 return(ret);
307 }
309 if ((ret = salld_data_mode_set_cmdl(inst)) != sa_ERR_OK)
310 {
311 return(ret);
312 }
314 SALLD_SET_STATE_TX_SC_VALID(&inst->salldInst, 1);
315 }
316 }
317 break;
319 /* Master key and Salt setup for ac */
320 case sa_CHAN_CTRL_KEY_CONFIG:
321 {
322 bitmap = ctrl->ctrlInfo.key.ctrlBitfield;
324 if (bitmap & sa_KEY_CONTROL_TX_KEY_VALID)
325 {
326 Sa_DataModeKeyParams_t* pKeyParams = &ctrl->ctrlInfo.key.txKey.data;
327 salldDataModeComInfo_t* pComInfo = &txInst->comInfo;
329 if(!salld_data_mode_setup_key(inst, pComInfo, pKeyParams))
330 return(sa_ERR_PARAMS);
331 }
332 }
333 break;
335 default:
336 return (sa_ERR_PARAMS);
338 }
339 return (sa_ERR_OK);
340 }
342 /******************************************************************************
343 * FUNCTION PURPOSE: Data Mode Get Stats
344 ******************************************************************************
345 * DESCRIPTION: Extract Data Mode related statistics from the instance structure
346 *
347 * void salld_data_mode_get_stats (
348 * void *salldInst, - A pointer to SALLD instance
349 * uint16_t flags, - various control flags
350 * void *stats) - The stat structure
351 *
352 * Return values: sa_ERR_OK
353 *
354 *****************************************************************************/
355 int16_t salld_data_mode_get_stats (void *salldInst, uint16_t flags, void *stats)
356 {
357 Sa_DataModeStats_t *pStats = (Sa_DataModeStats_t *) stats;
358 salldDataModeInst_t *inst = (salldDataModeInst_t *) salldInst;
359 salldDataModeTxInst_t *txInst = (salldDataModeTxInst_t *) &inst->txInst;
361 pStats->pktHi = txInst->packetMsw;
362 pStats->pktLo = txInst->packetLsw;
364 return (sa_ERR_OK);
365 }
367 static const uint8_t saKasumiF9PaddingUp[8] = {0x40, 0, 0, 0, 0, 0, 0, 0};
368 static const uint8_t saKasumiF9PaddingDown[8] = {0xC0, 0, 0, 0, 0, 0, 0, 0};
370 /******************************************************************************
371 * FUNCTION PURPOSE: Data Mode Send Data
372 ******************************************************************************
373 * DESCRIPTION:
374 *
375 * void salld_data_mode_send_data (
376 * void *salldInst, - A pointer to SALLD Data Mode instance
377 * void *pktInfo, - packet pointer
378 * uint16_t clear)
379 *
380 * Perform the following actions:
381 * - Update statistics
382 *
383 *****************************************************************************/
384 int16_t salld_data_mode_send_data (void *salldInst, void *pktInfo, uint16_t clear)
385 {
386 salldDataModeInst_t *inst = (salldDataModeInst_t *)salldInst;
387 salldDataModeTxInst_t *txInst = &inst->txInst;
388 Sa_PktInfo_t* pPktInfo = (Sa_PktInfo_t*)pktInfo;
389 int16_t ret_code;
391 /* Kasumi-F9 Padding:
392 * The SASS is not able to generate Kasumi-F9 padding when the number of bytes to be authenticated is multiple of 8.
393 * Therefore, we need to perform Kasumi-F9 padding for this special case
394 * Assumption:the padding bytes can be added to the end of data segments
395 */
396 if (txInst->authMode == sa_AuthMode_KASUMI_F9)
397 {
398 Sa_PayloadInfo_t *pPayloadInfo = &pPktInfo->payloadInfo;
399 uint8_t *pPadding;
401 if (!(pPayloadInfo->authSize & 0x7))
402 {
403 Sa_PktDesc_t *pPktDesc = &pPktInfo->pktDesc;
404 int paddingSegIndex = pPktDesc->nSegments - 1;
406 /* The authentication data is 8-byte aligned, padding is required */
407 if(pPktDesc->size != (pPayloadInfo->authSize + pPayloadInfo->authOffset))
408 return(sa_ERR_GEN);
410 if((pPktDesc->segAllocSizes[paddingSegIndex] - pPktDesc->segUsedSizes[paddingSegIndex]) < 8)
411 return(sa_ERR_GEN);
413 pPadding = (uint8_t *)pPktDesc->segments[paddingSegIndex];
414 pPadding += pPktDesc->segUsedSizes[paddingSegIndex];
416 memcpy(pPadding,
417 txInst->comInfo.config.enc?saKasumiF9PaddingDown:saKasumiF9PaddingUp,
418 8);
420 pPktDesc->size += 8;
421 pPktDesc->segUsedSizes[paddingSegIndex] += 8;
422 pPayloadInfo->authSize += 8;
423 }
425 }
427 /* Encrypt and Authenticate Packet(s) */
428 ret_code = salld_data_mode_update_cmdl(inst, pPktInfo);
430 if(ret_code != sa_ERR_OK)
431 return (ret_code);
433 /* Pass the software Info in the packet */
434 pPktInfo->validBitMap |= sa_PKT_INFO_VALID_SW_INFO;
435 pPktInfo->swInfo = txInst->swInfo;
437 if(++txInst->packetLsw == 0)
438 txInst->packetMsw++;
440 return(sa_ERR_OK);
442 } /* salld_data_mode_send_data */
444 /******************************************************************************
445 * FUNCTION PURPOSE: Data Mode Receive Data
446 ******************************************************************************
447 * DESCRIPTION:
448 *
449 * void salld_data_mode_receive_data (
450 * void *salldInst, - A pointer to SALLD instance
451 * void *pktInfo) - packet pointer
452 *
453 * Not Supported
454 *****************************************************************************/
455 int16_t salld_data_mode_receive_data (void *salldInst, void *pktInfo)
456 {
457 /* Kasumi-F9 De-Padding */
458 salldDataModeInst_t *inst = (salldDataModeInst_t *)salldInst;
459 salldDataModeTxInst_t *txInst = &inst->txInst;
460 Sa_PktInfo_t* pPktInfo = (Sa_PktInfo_t*)pktInfo;
462 /* Kasumi-F9 Padding:
463 * The SASS is not able to generate Kasumi-F9 padding when the number of bytes to be authenticated is multiple of 8.
464 * Therefore, we need to perform Kasumi-F9 padding for this special case
465 */
466 if (txInst->authMode == sa_AuthMode_KASUMI_F9)
467 {
468 Sa_PayloadInfo_t *pPayloadInfo = &pPktInfo->payloadInfo;
470 if (!(pPayloadInfo->authSize & 0x7))
471 {
472 Sa_PktDesc_t *pPktDesc = &pPktInfo->pktDesc;
473 int paddingSegIndex = pPktDesc->nSegments - 1;
474 int numBytes = 8;
476 pPktDesc->size -= 8;
478 while (numBytes)
479 {
480 if (pPktDesc->segUsedSizes[paddingSegIndex] >= numBytes)
481 {
482 pPktDesc->segUsedSizes[paddingSegIndex] -= numBytes;
483 numBytes = 0;
484 }
485 else
486 {
487 numBytes -= pPktDesc->segUsedSizes[paddingSegIndex];
488 pPktDesc->segUsedSizes[paddingSegIndex] = 0;
489 if (paddingSegIndex)
490 {
491 paddingSegIndex--;
492 }
493 else
494 {
495 return(sa_ERR_GEN);
496 }
498 }
499 }
500 }
502 }
504 return (sa_ERR_OK);
505 }
507 /****************************************************************************
508 * FUNCTION PURPOSE: Construct Data Mode Security Context
509 ****************************************************************************
510 * DESCRIPTION: Construct Security Context from the configuration parameters
511 * for Data Mode (to-SA) operations
512 *
513 * uint16_t salld_data_mode_set_sc(
514 * salldIpsecInst_t* inst) -> Point to Data Mode channel instance
515 *
516 * Return values: sa_ERR_XXX
517 *
518 * Assumption: The same algorithm will be used for both encryption and
519 * authentication
520 *
521 ***************************************************************************/
522 int16_t salld_data_mode_set_sc(salldDataModeInst_t *inst)
523 {
524 salldObj_t *sysInst = (salldObj_t *)sa_CONV_OFFSET_TO_ADDR(salldLObj.instPoolBaseAddr, inst->salldInst.ownerInstOffset);
525 salldDataModeTxInst_t *txInst = &inst->txInst;
526 salldDataModeComInfo_t *pComInfo = &txInst->comInfo;
527 Sa_DataModeConfigParams_t *pConfig = &pComInfo->config;
528 Sa_ScReqInfo_t* pScInfo = &txInst->scInfo;
529 int16_t encCmdlSize, encScSize, encScOffset;
530 int16_t authCmdlSize, authScSize, authScOffset;
531 #if !defined(NSS_LITE) && !defined(NSS_LITE2)
532 int16_t acAlgorithm = SA_AC_ALGORITHM_GSM_A53;
533 #endif
534 saDMAReqInfo_t dmaReqInfo;
535 uint16_t useEnc;
536 uint16_t fRandomIV;
537 uint8_t firstEngId;
538 uint8_t tagSize;
539 #ifdef NSS_LITE2
540 uint32_t ctxAttrCtrlBitMap;
541 #endif
543 /*
544 * Calculate the security Context Size and allocate security Context
545 *
546 */
547 salld_sc_enc_get_info(txInst->cipherMode, pConfig->ivSize, &encCmdlSize, &encScSize, &pComInfo->encEngId, &fRandomIV, SALLD_TEST_SASS_GEN2(sysInst));
548 salld_sc_auth_get_info(txInst->authMode, &useEnc, &authCmdlSize, &authScSize, &pComInfo->authEngId);
549 pScInfo->scSize = SA_CTX_PHP_DATA_MODE_SIZE + encScSize + authScSize;
550 salldLObj.callOutFuncs.ScAlloc((Sa_ChanHandle)sa_CONV_ADDR_TO_OFFSET(salldLObj.instPoolBaseAddr,inst), pScInfo);
552 /* Fix the encrpytion engine ID that is set to use from Encryption Engine
553 when auth engine ID is Air Cipher OR if the channel is Air Cipher */
554 if (pComInfo->encEngId == SALLD_CMDL_ENGINE_ID_ES1)
555 {
556 if (((pConfig->ctrlBitMap & sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG) == sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG) ||
557 (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ACS1))
558 {
559 pComInfo->encEngId = SALLD_CMDL_ENGINE_ID_ACS1;
560 }
561 }
563 #if !defined(NSS_LITE) && !defined(NSS_LITE2)
564 if (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ES1)
565 {
566 if ((pConfig->ctrlBitMap & sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG) == sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG)
567 {
568 pComInfo->authEngId = SALLD_CMDL_ENGINE_ID_ACS1;
569 }
570 }
571 #endif
573 if(pScInfo->scBuf == (uintptr_t) NULL)
574 return(sa_ERR_NO_CTX_BUF);
576 Sa_osalBeginScAccess((void *)pScInfo->scBuf, pScInfo->scSize);
578 memset((void *) pScInfo->scBuf, 0, SALLD_BYTE_TO_WORD(pScInfo->scSize));
580 /* Prepare PHP Security Context */
581 memset(&dmaReqInfo, 0, sizeof(saDMAReqInfo_t));
582 dmaReqInfo.phpFetchSize = SA_CTX_DMA_SIZE_64;
583 /* Non-Air Ciphering condition */
584 if ((!useEnc) || pConfig->enc1st)
585 {
586 dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
587 dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
588 encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
589 authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + encScSize);
590 }
591 else
592 {
593 dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
594 dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
595 authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
596 encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + authScSize);
598 }
600 /* Air Ciphering condition */
601 /* Assumption: Air Ciphering algorithm will be used as a pair */
602 if (pConfig->enc1st && (pComInfo->encEngId == SALLD_CMDL_ENGINE_ID_ACS1))
603 {
604 dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
605 dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
606 encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
607 authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + encScSize);
608 }
609 else if (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ACS1)
610 {
611 dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
612 dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
613 authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
614 encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + authScSize);
615 }
617 dmaReqInfo.phpEvictSize = SA_CTX_DMA_SIZE_64;
619 #ifdef NSS_LITE2
620 if (pConfig->ctrlBitMap & sa_DM_CONFIG_PROMOTE_CHANNEL)
621 {
622 ctxAttrCtrlBitMap = SA_CTX_SA2UL_ALLOW_PROMOTE | SA_CTX_SA2UL_SECURE;
623 }
624 else if (pConfig->ctrlBitMap & sa_DM_CONFIG_DEMOTE_CHANNEL)
625 {
626 ctxAttrCtrlBitMap = SA_CTX_SA2UL_ALLOW_DEMOTE | SA_CTX_SA2UL_SECURE;
627 }
628 else if (pConfig->ctrlBitMap & sa_DM_CONFIG_USE_SECURE_CTX_FOR_NON_SECURE_CHANNEL)
629 {
630 ctxAttrCtrlBitMap = SA_CTX_SA2UL_ALLOW_NONSEC | SA_CTX_SA2UL_SECURE;
631 }
632 else
633 {
634 ctxAttrCtrlBitMap = 0;
635 }
637 salld_set_sc_scctl(&dmaReqInfo, &txInst->destInfo, SA_CTX_PKT_TYPE_NONE,
638 pScInfo->scID, (tword *) pScInfo->scBuf, ctxAttrCtrlBitMap);
639 #else
640 {
641 salld_set_sc_phpCommom(&dmaReqInfo, &txInst->destInfo, SA_CTX_PKT_TYPE_NONE,
642 pScInfo->scID, (tword *) pScInfo->scBuf);
643 }
644 #endif
646 /* Prepare Security Context for the encryption Engine */
647 if (encScSize)
648 {
649 #if !defined(NSS_LITE) && !defined(NSS_LITE2)
650 if (pComInfo->encEngId == SALLD_CMDL_ENGINE_ID_ACS1)
651 {
652 salld_set_sc_acEnc(txInst->cipherMode, pConfig->sessionEncKeySize,
653 pComInfo->sessionEncKey, NULL, pConfig->enc,
654 (tword *)pScInfo->scBuf + encScOffset,
655 &acAlgorithm, SALLD_TEST_SASS_GEN2(sysInst));
656 }
657 else
658 #endif
659 {
661 salld_set_sc_enc(sa_PT_NULL, txInst->cipherMode, pConfig->sessionEncKeySize,
662 pComInfo->sessionEncKey, (uint8_t) pConfig->aadSize, pConfig->enc,
663 (tword *)pScInfo->scBuf + encScOffset);
664 }
665 }
667 /* Prepare Security Context for the authentication Engine */
668 if (authScSize)
669 {
670 #if !defined(NSS_LITE) && !defined(NSS_LITE2)
671 if (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ACS1)
672 {
673 salld_set_sc_acAuth(txInst->authMode, pConfig->sessionMacKeySize,
674 pComInfo->sessionMacKey,
675 (tword *) pScInfo->scBuf + authScOffset,
676 &acAlgorithm,
677 pConfig->enc?SA_KASUMI_AUTH_DIR1:SA_KASUMI_AUTH_DIR0,
678 SALLD_TEST_SASS_GEN2(sysInst));
679 }
680 else
681 #endif
682 {
683 if (useEnc)
684 {
685 salld_set_sc_enc(sa_PT_NULL, txInst->authMode, pConfig->sessionMacKeySize,
686 pComInfo->sessionMacKey, (uint8_t) pConfig->aadSize, FALSE,
687 (tword *) pScInfo->scBuf + authScOffset);
689 }
690 else
691 {
692 salld_set_sc_auth(txInst->authMode, pConfig->sessionMacKeySize,
693 pComInfo->sessionMacKey,
694 (tword *) pScInfo->scBuf + authScOffset);
695 }
696 }
697 }
699 if ((pComInfo->encEngId == SALLD_CMDL_ENGINE_NONE) && (pComInfo->authEngId == SALLD_CMDL_ENGINE_NONE))
700 {
701 firstEngId = SALLD_CMDL_FINAL_ENGINE_ID;
702 }
703 else if ((pComInfo->encEngId == SALLD_CMDL_ENGINE_NONE))
704 {
705 firstEngId = pComInfo->authEngId;
706 }
707 else if ((pComInfo->authEngId == SALLD_CMDL_ENGINE_NONE))
708 {
709 firstEngId = pComInfo->encEngId;
710 }
711 else
712 {
713 firstEngId = pConfig->enc1st?pComInfo->encEngId:pComInfo->authEngId;
714 }
716 tagSize = SALLD_ROUND_UP(pConfig->macSize, 8);
718 #ifdef SALLD_DATA_MODE_USE_PHP
719 /* Construct the Data Mode specific Security Context */
720 {
721 tword* ctxIn = (tword *)(pScInfo->scBuf + SALLD_BYTE_TO_WORD(SA_CTX_PHP_COMMON_SIZE));
723 pktWrite16bits_m(ctxIn, SALLD_FIELDOFFSET(saCtxProtoDm_t, firstEngIdTagSize),
724 SALLD_MK_UINT16(firstEngId, tagSize));
726 }
727 #endif
729 /* Security Context swizzling */
730 salld_swiz_128((uint8_t*) pScInfo->scBuf, (uint8_t*) pScInfo->scBuf, pScInfo->scSize);
732 Sa_osalEndScAccess((void *)pScInfo->scBuf, pScInfo->scSize);
734 /* Prepare the SW Info Words */
735 #ifndef SALLD_DATA_MODE_USE_PHP
736 #if defined(NSS_LITE2)
737 salld_set_swInfo2(firstEngId, 0,
738 &txInst->destInfo,
739 pScInfo, &txInst->swInfo, tagSize);
740 #else
741 salld_set_swInfo(firstEngId, 0,
742 &txInst->destInfo,
743 pScInfo, &txInst->swInfo, tagSize);
744 #endif
745 #else
746 /* Data packets enter PHP engine */
747 salld_set_swInfo(SALLD_CMDL_ENGINE_SRTP_AC_HPS1, 0,
748 &txInst->destInfo,
749 pScInfo, &txInst->swInfo, 0);
750 #endif
751 /* Store the scBuf internally as offset to suppor multiprocess */
752 pScInfo->scBuf = (uintptr_t) sa_CONV_ADDR_TO_OFFSET(salldLObj.scPoolBaseAddr, pScInfo->scBuf);
754 return (sa_ERR_OK);
755 }
757 /****************************************************************************
758 * FUNCTION PURPOSE: Data Mode Get SwInfo
759 ****************************************************************************
760 * DESCRIPTION: Data Mode Get SwInfo
761 *
762 * int16_t salld_data_mode_get_swInfo (
763 * Sa_ChanHandle handle - SALLD channel identifier
764 * uint16_t dir - packet directions
765 * Sa_SWInfo_t *pSwInfo) - a pointer to swInfo
766 *
767 * Return values: sa_ERR_OK
768 * sa_ERR_GEN
769 * sa_ERR_PARAMS
770 * sa_ERR_UNSUPPORTED
771 *
772 ***************************************************************************/
773 int16_t salld_data_mode_get_swInfo (void *salldInst, uint16_t dir, Sa_SWInfo_t* pChanSwInfo)
774 {
775 salldDataModeInst_t *inst = (salldDataModeInst_t *)salldInst;
776 int16_t ret = sa_ERR_OK;
778 if (dir == sa_PKT_DIR_TO_NETWORK)
779 {
780 salldDataModeTxInst_t *txInst = (salldDataModeTxInst_t *) &inst->txInst;
781 memcpy(pChanSwInfo, &txInst->swInfo, sizeof(Sa_SWInfo_t));
782 }
783 else
784 {
785 ret = sa_ERR_PARAMS;
786 }
788 return(ret);
789 }
791 /****************************************************************************
792 * Table PURPOSE: Data Mode function call table
793 ****************************************************************************
794 * DESCRIPTION: The tables are used to link Data Mode functions to the
795 * SALLD library if required
796 *
797 ***************************************************************************/
798 Sa_ProtocolCallTbl_t Sa_callTblDataMode =
799 {
800 sa_PT_NULL,
801 salld_data_mode_init,
802 salld_data_mode_control,
803 salld_data_mode_get_stats,
804 salld_data_mode_send_data,
805 salld_data_mode_receive_data,
806 salld_data_mode_close,
807 salld_data_mode_get_swInfo
808 };
811 /* Nothing past this point */