]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/sa-lld.git/blob - src/proto/datamode/sallddm.c
Merge pull request #1 in PROCESSOR-SDK/sa-lld from PRSDK-1481 to master
[keystone-rtos/sa-lld.git] / src / proto / datamode / sallddm.c
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;
75     
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   }
81   
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   }
87   
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)
116     
117     /* Common Check */
118     if((pDataModeConfig->sessionEncKeySize > 32) ||
119        (pDataModeConfig->sessionMacKeySize > 32))
120         return (FALSE);
122 #ifdef NSS_LITE
123     /* NSS LITE devices do not have Air Cipher Engines */
124     if ((pDataModeConfig->ctrlBitMap & sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG) == sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG)
125       return (FALSE);
126 #endif
128     if((authMode == sa_AuthMode_NULL) && 
129        ((cipherMode != sa_CipherMode_GCM) &&
130         (cipherMode != sa_CipherMode_CCM)))
131     {
132         if(pDataModeConfig->macSize != 0)
133             return(FALSE);
134     }    
135     
136     /* Ciphering mode specific check */
137     switch (cipherMode)
138     {
139         case sa_CipherMode_CCM:
140             if(((pDataModeConfig->ivSize                + \
141                  pDataModeConfig->sessionSaltSize) > 13) ||
142                 (pDataModeConfig->aadSize > 14)         ||
143                 (authMode != sa_AuthMode_NULL))
144                 return (FALSE);    
145             break;
146         
147         case sa_CipherMode_DES_CBC:
148         case sa_CipherMode_3DES_CBC:
149             if((pDataModeConfig->ivSize != 8)          ||
150                (pDataModeConfig->sessionSaltSize != 0))  
151                 return (FALSE);    
152             break;    
153             
154         case sa_CipherMode_GCM:
155             if(((pDataModeConfig->ivSize                 + \
156                  pDataModeConfig->sessionSaltSize) != 12) ||
157                 (pDataModeConfig->aadSize > 16)           ||
158                 (authMode != sa_AuthMode_NULL))
159                 return (FALSE);    
160             break;
161             
162 #ifndef NSS_LITE            
163         case sa_CipherMode_KASUMI_F8:
164             if((pDataModeConfig->ivSize != 8))
165                 return (FALSE);    
166             break;
167             
168         case sa_CipherMode_SNOW3G_F8:
169             if((pDataModeConfig->ivSize != 16))
170                 return (FALSE);    
171             break;
172             
173         case sa_CipherMode_AES_CTR:
174         case sa_CipherMode_AES_F8:
175         case sa_CipherMode_AES_CBC:
176         case sa_CipherMode_GSM_A53:
177         case sa_CipherMode_ECSD_A53:
178         case sa_CipherMode_GEA3:
179         case sa_CipherMode_NULL:
180             break;     
181         
182 #else
183         case sa_CipherMode_AES_CTR:
184         case sa_CipherMode_AES_F8:
185         case sa_CipherMode_AES_CBC:
186         case sa_CipherMode_NULL:
187             break;     
189 #endif        
190         
191         default:
192             return (FALSE);
193     }
194     
195     /* Encryption mode specific check */
196     switch (authMode)
197     {
198         case sa_AuthMode_GMAC:
199           if(((pDataModeConfig->ivSize                 + \
200                pDataModeConfig->sessionSaltSize) != 12) ||
201               (pDataModeConfig->aadSize > 16)           ||
202                (cipherMode != sa_CipherMode_NULL)) 
203               return (FALSE);   
204             break;
205             
206         case sa_AuthMode_GMAC_AH:
207             if((pDataModeConfig->ivSize != 8)          ||
208                (pDataModeConfig->sessionSaltSize != 4) ||
209                (cipherMode != sa_CipherMode_NULL)) 
210                return (FALSE);
211             break;
212             
213         case sa_AuthMode_KASUMI_F9:
214             if((pDataModeConfig->ivSize != 8))
215                return (FALSE);
216             break;
217             
218         case sa_AuthMode_MD5:
219         case sa_AuthMode_SHA1:
220         case sa_AuthMode_SHA2_224:
221         case sa_AuthMode_SHA2_256:
222         case sa_AuthMode_HMAC_MD5:
223         case sa_AuthMode_HMAC_SHA1:
224         case sa_AuthMode_HMAC_SHA2_224:
225         case sa_AuthMode_HMAC_SHA2_256:
226         case sa_AuthMode_CMAC:
227         case sa_AuthMode_CBC_MAC:
228         case sa_AuthMode_AES_XCBC:
229         case sa_AuthMode_NULL:
230             break;
231             
232         default:
233             return(FALSE);
234     }
235     
237   return TRUE;
238 }            
239            
241 /****************************************************************************
242  * FUNCTION PURPOSE: Data Mode Control 
243  ****************************************************************************
244  * DESCRIPTION: Data Mode Control functions
245  *
246  * int16_t  salld_data_mode_control (
247  *   void  *salldInst  - a pointer to SALLD channel instance
248  *   void  *ctrl)      - a pointer to control structure
249  *
250  * Return values:  sa_ERR_OK
251  *                 sa_ERR_GEN
252  *                 sa_ERR_PARAMS
253  *
254  ***************************************************************************/
255 int16_t salld_data_mode_control (void *salldInst, void *salldCtrl)
257   salldDataModeInst_t *inst = (salldDataModeInst_t *)salldInst;
258   salldDataModeTxInst_t *txInst = &inst->txInst;
259   Sa_ChanCtrlInfo_t *ctrl = (Sa_ChanCtrlInfo_t *)salldCtrl;
260   uint16_t bitmap;
261   int16_t ret;
263   switch(ctrl->ctrlType)
264   {
265     /* SALLD cipher, mac and key size selection */
266     case sa_CHAN_CTRL_GEN_CONFIG:
267     {
268         bitmap = ctrl->ctrlInfo.gen.validBitfield;
269         if( bitmap & sa_CONTROLINFO_VALID_TX_CTRL)
270         {
271             /* Input parameters check */
272             Sa_GenConfigParams_t* pGenConfig = &ctrl->ctrlInfo.gen.txCtrl;
273             Sa_DataModeConfigParams_t*  pDataModeConfig  = &ctrl->ctrlInfo.gen.txCtrl.params.data;
274             
275             if (salld_dm_verify_config_params(pGenConfig->cipherMode, pGenConfig->authMode, pDataModeConfig))
276             {
277                 txInst->cipherMode = pGenConfig->cipherMode;
278                 txInst->authMode   = pGenConfig->authMode;
279                 txInst->destInfo   = pGenConfig->destInfo; 
280                 txInst->comInfo.config = *pDataModeConfig;
281                 if(txInst->cipherMode == sa_CipherMode_NULL)
282                     txInst->comInfo.config.enc1st = FALSE;    
283             }
284             else
285             {
286                 return(sa_ERR_PARAMS);
287             }    
288         }
289         
290         /*
291          * Is it time to form and register security context?
292          */
293         if(!SALLD_TEST_STATE_TX_SC_VALID(&inst->salldInst) && 
294             SALLD_TEST_STATE_TX_ON(&inst->salldInst))
295         {
296             if ((ret = salld_data_mode_set_sc(inst)) != sa_ERR_OK)
297             {
298                 return(ret);
299             }
300             
301             if ((ret = salld_data_mode_set_cmdl(inst)) != sa_ERR_OK)
302             {
303                 return(ret);
304             }
305             
306             SALLD_SET_STATE_TX_SC_VALID(&inst->salldInst, 1);
307         } 
308     }    
309     break;
311     /* Master key and Salt setup for ac */
312     case sa_CHAN_CTRL_KEY_CONFIG:
313     {
314         bitmap = ctrl->ctrlInfo.key.ctrlBitfield;
315         
316         if (bitmap & sa_KEY_CONTROL_TX_KEY_VALID)
317         {
318             Sa_DataModeKeyParams_t* pKeyParams = &ctrl->ctrlInfo.key.txKey.data;
319             salldDataModeComInfo_t*   pComInfo = &txInst->comInfo;
320             
321             if(!salld_data_mode_setup_key(inst, pComInfo, pKeyParams))
322                 return(sa_ERR_PARAMS);
323         }    
324     }   
325     break;
326     
327     default:
328         return (sa_ERR_PARAMS);
330   }
331   return (sa_ERR_OK);
334 /******************************************************************************
335  * FUNCTION PURPOSE: Data Mode Get Stats
336  ******************************************************************************
337  * DESCRIPTION: Extract Data Mode related statistics from the instance structure
338  *
339  * void salld_data_mode_get_stats (
340  *    void   *salldInst,       - A pointer to SALLD instance
341  *    uint16_t flags,            - various control flags
342  *    void   *stats)           - The stat structure
343  *
344  * Return values:  sa_ERR_OK
345  *
346  *****************************************************************************/
347 int16_t salld_data_mode_get_stats (void *salldInst, uint16_t flags, void *stats)
349   Sa_DataModeStats_t  *pStats = (Sa_DataModeStats_t *)  stats;
350   salldDataModeInst_t   *inst   = (salldDataModeInst_t *)   salldInst; 
351   salldDataModeTxInst_t *txInst = (salldDataModeTxInst_t *) &inst->txInst;
353   pStats->pktHi  = txInst->packetMsw;
354   pStats->pktLo  = txInst->packetLsw;
356   return (sa_ERR_OK);
359 static const uint8_t saKasumiF9PaddingUp[8]   = {0x40, 0, 0, 0, 0, 0, 0, 0};
360 static const uint8_t saKasumiF9PaddingDown[8] = {0xC0, 0, 0, 0, 0, 0, 0, 0};
362 /******************************************************************************
363  * FUNCTION PURPOSE: Data Mode Send Data
364  ******************************************************************************
365  * DESCRIPTION: 
366  *
367  * void salld_data_mode_send_data (
368  *    void *salldInst,      - A pointer to SALLD Data Mode instance
369  *    void *pktInfo,        - packet pointer
370  *    uint16_t clear) 
371  *
372  *  Perform the following actions:
373  *      - Update statistics
374  *
375  *****************************************************************************/
376 int16_t salld_data_mode_send_data (void *salldInst, void *pktInfo, uint16_t clear) 
378   salldDataModeInst_t *inst   = (salldDataModeInst_t *)salldInst; 
379   salldDataModeTxInst_t *txInst = &inst->txInst;
380   Sa_PktInfo_t* pPktInfo = (Sa_PktInfo_t*)pktInfo;
381   int16_t ret_code;
382   
383   /* Kasumi-F9 Padding:
384    * The SASS is not able to generate Kasumi-F9 padding when the number of bytes to be authenticated is multiple of 8.
385    * Therefore, we need to perform Kasumi-F9 padding for this special case 
386    * Assumption:the padding bytes can be added to the end of data segments
387    */
388   if (txInst->authMode == sa_AuthMode_KASUMI_F9)
389   {
390     Sa_PayloadInfo_t *pPayloadInfo = &pPktInfo->payloadInfo;
391     uint8_t *pPadding;
392     
393     if (!(pPayloadInfo->authSize & 0x7))
394     {
395         Sa_PktDesc_t *pPktDesc = &pPktInfo->pktDesc;
396         int paddingSegIndex = pPktDesc->nSegments - 1;        
397         
398         /* The authentication data is 8-byte aligned, padding is required */
399         if(pPktDesc->size != (pPayloadInfo->authSize + pPayloadInfo->authOffset))
400             return(sa_ERR_GEN);
401             
402         if((pPktDesc->segAllocSizes[paddingSegIndex] - pPktDesc->segUsedSizes[paddingSegIndex]) < 8)
403             return(sa_ERR_GEN);
404             
405         pPadding = (uint8_t *)pPktDesc->segments[paddingSegIndex];
406         pPadding += pPktDesc->segUsedSizes[paddingSegIndex];    
407             
408         memcpy(pPadding,
409                txInst->comInfo.config.enc?saKasumiF9PaddingDown:saKasumiF9PaddingUp,
410                8);        
411             
412         pPktDesc->size += 8;
413         pPktDesc->segUsedSizes[paddingSegIndex] += 8;
414         pPayloadInfo->authSize += 8;
415     }
416   
417   }
419   /* Encrypt and Authenticate Packet(s) */
420   ret_code = salld_data_mode_update_cmdl(inst, pPktInfo);
421   
422   if(ret_code != sa_ERR_OK)
423     return (ret_code);  
424     
425   /* Pass the software Info in the packet */
426   pPktInfo->validBitMap |= sa_PKT_INFO_VALID_SW_INFO;
427   pPktInfo->swInfo = txInst->swInfo;
428   
429   if(++txInst->packetLsw == 0)
430     txInst->packetMsw++;
431     
432   return(sa_ERR_OK);
433       
434 } /* salld_data_mode_send_data */
436 /******************************************************************************
437  * FUNCTION PURPOSE: Data Mode Receive Data
438  ******************************************************************************
439  * DESCRIPTION: 
440  *
441  * void salld_data_mode_receive_data (
442  *    void *salldInst,    - A pointer to SALLD instance
443  *    void *pktInfo)      - packet pointer
444  * 
445  * Not Supported
446  *****************************************************************************/
447 int16_t salld_data_mode_receive_data (void *salldInst, void *pktInfo) 
449   /* Kasumi-F9 De-Padding */
450   salldDataModeInst_t *inst   = (salldDataModeInst_t *)salldInst; 
451   salldDataModeTxInst_t *txInst = &inst->txInst;
452   Sa_PktInfo_t* pPktInfo = (Sa_PktInfo_t*)pktInfo;
453   
454   /* Kasumi-F9 Padding:
455    * The SASS is not able to generate Kasumi-F9 padding when the number of bytes to be authenticated is multiple of 8.
456    * Therefore, we need to perform Kasumi-F9 padding for this special case 
457    */
458   if (txInst->authMode == sa_AuthMode_KASUMI_F9)
459   {
460     Sa_PayloadInfo_t *pPayloadInfo = &pPktInfo->payloadInfo;
461     
462     if (!(pPayloadInfo->authSize & 0x7))
463     {
464         Sa_PktDesc_t *pPktDesc = &pPktInfo->pktDesc;
465         int paddingSegIndex = pPktDesc->nSegments - 1;
466         int numBytes = 8;  
467         
468         pPktDesc->size -= 8;
469         
470         while (numBytes)
471         {
472             if (pPktDesc->segUsedSizes[paddingSegIndex] >= numBytes)
473             {
474                 pPktDesc->segUsedSizes[paddingSegIndex] -= numBytes;
475                 numBytes = 0;    
476             }
477             else
478             {
479                 numBytes -= pPktDesc->segUsedSizes[paddingSegIndex];
480                 pPktDesc->segUsedSizes[paddingSegIndex] = 0;
481                 if (paddingSegIndex)
482                 {
483                     paddingSegIndex--;    
484                 }
485                 else
486                 {
487                     return(sa_ERR_GEN);
488                 }
489                     
490             }
491         }
492     }
493   
494   }
496   return (sa_ERR_OK);
499 /****************************************************************************
500  * FUNCTION PURPOSE: Construct Data Mode Security Context
501  ****************************************************************************
502  * DESCRIPTION: Construct Security Context from the configuration parameters 
503  *          for Data Mode (to-SA) operations
504  *
505  *  uint16_t salld_data_mode_set_sc(
506  *            salldIpsecInst_t*     inst)      -> Point to Data Mode channel instance
507  *                       
508  * Return values: sa_ERR_XXX
509  * 
510  * Assumption: The same algorithm will be used for both encryption and 
511  *             authentication                          
512  *
513  ***************************************************************************/
514 int16_t salld_data_mode_set_sc(salldDataModeInst_t *inst) 
516   salldObj_t *sysInst = (salldObj_t *)sa_CONV_OFFSET_TO_ADDR(salldLObj.instPoolBaseAddr, inst->salldInst.ownerInstOffset);
517   salldDataModeTxInst_t *txInst = &inst->txInst;
518   salldDataModeComInfo_t *pComInfo = &txInst->comInfo;
519   Sa_DataModeConfigParams_t  *pConfig = &pComInfo->config;
520   Sa_ScReqInfo_t* pScInfo = &txInst->scInfo;
521   int16_t encCmdlSize, encScSize, encScOffset;
522   int16_t authCmdlSize, authScSize, authScOffset;
523 #ifndef NSS_LITE   
524   int16_t acAlgorithm = SA_AC_ALGORITHM_GSM_A53;
525 #endif
526   saDMAReqInfo_t dmaReqInfo;
527   uint16_t useEnc;
528   uint16_t fRandomIV;
529   uint8_t firstEngId;
530   uint8_t tagSize;
531   
532   /*
533    * Calculate the security Context Size and allocate security Context
534    *
535    */
536   salld_sc_enc_get_info(txInst->cipherMode, pConfig->ivSize, &encCmdlSize, &encScSize, &pComInfo->encEngId, &fRandomIV, SALLD_TEST_SASS_GEN2(sysInst)); 
537   salld_sc_auth_get_info(txInst->authMode, &useEnc, &authCmdlSize, &authScSize, &pComInfo->authEngId);
538   pScInfo->scSize = SA_CTX_PHP_DATA_MODE_SIZE + encScSize + authScSize;
539   salldLObj.callOutFuncs.ScAlloc((Sa_ChanHandle)sa_CONV_ADDR_TO_OFFSET(salldLObj.instPoolBaseAddr,inst), pScInfo);
541   /* Fix the encrpytion engine ID that is set to use from Encryption Engine
542      when auth engine ID is Air Cipher OR if the channel is Air Cipher */
543   if (pComInfo->encEngId  == SALLD_CMDL_ENGINE_ID_ES1)
544   {
545     if (((pConfig->ctrlBitMap & sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG) == sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG)  ||
546          (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ACS1))
547     {
548       pComInfo->encEngId = SALLD_CMDL_ENGINE_ID_ACS1;
549     }
550   }
552 #ifndef NSS_LITE
553   if (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ES1)
554   {
555     if ((pConfig->ctrlBitMap & sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG) == sa_DM_CONFIG_SELECT_AIR_CIPHER_ENG)
556     {
557       pComInfo->authEngId = SALLD_CMDL_ENGINE_ID_ACS1;
558     }
559   }
560 #endif
562   if(pScInfo->scBuf == NULL)
563     return(sa_ERR_NO_CTX_BUF);
564     
565   Sa_osalBeginScAccess((void *)pScInfo->scBuf, pScInfo->scSize);
566   
567   memset(pScInfo->scBuf, 0, SALLD_BYTE_TO_WORD(pScInfo->scSize));
568   
569   /* Prepare PHP Security Context */
570   memset(&dmaReqInfo, 0, sizeof(saDMAReqInfo_t));
571   dmaReqInfo.phpFetchSize = SA_CTX_DMA_SIZE_64;
572   /* Non-Air Ciphering condition */
573   if ((!useEnc) || pConfig->enc1st)
574   {
575     dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
576     dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
577     encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
578     authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + encScSize);
579   }
580   else
581   {
582     dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
583     dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
584     authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
585     encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + authScSize);
586     
587   }
588   
589   /* Air Ciphering condition */
590   /* Assumption: Air Ciphering algorithm will be used as a pair */
591   if (pConfig->enc1st && (pComInfo->encEngId == SALLD_CMDL_ENGINE_ID_ACS1))
592   {
593     dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
594     dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
595     encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
596     authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + encScSize);
597   }
598   else if (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ACS1)
599   {
600     dmaReqInfo.engFetchSize[0] = SA_CTX_SIZE_TO_DMA_SIZE(authScSize);
601     dmaReqInfo.engFetchSize[1] = SA_CTX_SIZE_TO_DMA_SIZE(encScSize);
602     authScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE);
603     encScOffset = SALLD_BYTE_TO_WORD(SA_CTX_PHP_DATA_MODE_SIZE + authScSize);
604   }
605   
606   dmaReqInfo.phpEvictSize =  SA_CTX_DMA_SIZE_64;
607   
608   salld_set_sc_phpCommom(&dmaReqInfo, &txInst->destInfo, SA_CTX_PKT_TYPE_NONE,
609                          pScInfo->scID, pScInfo->scBuf);  
610                       
611   /* Prepare Security Context for the encryption Engine */
612   if (encScSize)
613   {
614     #ifndef NSS_LITE 
615     if (pComInfo->encEngId == SALLD_CMDL_ENGINE_ID_ACS1)
616     {
617         salld_set_sc_acEnc(txInst->cipherMode, pConfig->sessionEncKeySize, 
618                            pComInfo->sessionEncKey, NULL, pConfig->enc,
619                            pScInfo->scBuf + encScOffset,
620                            &acAlgorithm, SALLD_TEST_SASS_GEN2(sysInst));
621     }
622     else
623     #endif 
624     {
625     
626         salld_set_sc_enc(sa_PT_NULL, txInst->cipherMode, pConfig->sessionEncKeySize, 
627                          pComInfo->sessionEncKey, (uint8_t) pConfig->aadSize, pConfig->enc, 
628                          pScInfo->scBuf + encScOffset);
629     }               
630   }
631   
632   /* Prepare Security Context for the authentication Engine */
633   if (authScSize)
634   {
635     #ifndef NSS_LITE
636     if (pComInfo->authEngId == SALLD_CMDL_ENGINE_ID_ACS1)
637     {
638         salld_set_sc_acAuth(txInst->authMode, pConfig->sessionMacKeySize, 
639                             pComInfo->sessionMacKey, 
640                             pScInfo->scBuf + authScOffset,
641                             &acAlgorithm,
642                             pConfig->enc?SA_KASUMI_AUTH_DIR1:SA_KASUMI_AUTH_DIR0,
643                             SALLD_TEST_SASS_GEN2(sysInst));
644     }  
645     else
646     #endif
647     {
648         if (useEnc)
649         {
650             salld_set_sc_enc(sa_PT_NULL, txInst->authMode, pConfig->sessionMacKeySize, 
651                           pComInfo->sessionMacKey, (uint8_t) pConfig->aadSize, FALSE,
652                           pScInfo->scBuf + authScOffset);
653     
654         }
655         else
656         {
657             salld_set_sc_auth(txInst->authMode, pConfig->sessionMacKeySize, 
658                           pComInfo->sessionMacKey, 
659                           pScInfo->scBuf + authScOffset);
660         }               
661     }                     
662   }
663   
664   if ((pComInfo->encEngId == SALLD_CMDL_ENGINE_NONE) && (pComInfo->authEngId == SALLD_CMDL_ENGINE_NONE))
665   {
666     firstEngId = SALLD_CMDL_FINAL_ENGINE_ID;
667   }
668   else
669   {
670     firstEngId = pConfig->enc1st?pComInfo->encEngId:pComInfo->authEngId;
671   }
673   tagSize = SALLD_ROUND_UP(pConfig->macSize, 8);
674   
675   #ifdef SALLD_DATA_MODE_USE_PHP
676   /* Construct the Data Mode specific Security Context */    
677   {
678     tword* ctxIn = pScInfo->scBuf + SALLD_BYTE_TO_WORD(SA_CTX_PHP_COMMON_SIZE);
679   
680     pktWrite16bits_m(ctxIn, SALLD_FIELDOFFSET(saCtxProtoDm_t, firstEngIdTagSize), 
681                      SALLD_MK_UINT16(firstEngId, tagSize));
682                                      
683   }
684   #endif
685   
686   /* Security Context swizzling */
687   salld_swiz_128(pScInfo->scBuf, pScInfo->scBuf, pScInfo->scSize);
688   
689   Sa_osalEndScAccess((void *)pScInfo->scBuf, pScInfo->scSize);
690   
691   /* Prepare the SW Info Words */
692   #ifndef SALLD_DATA_MODE_USE_PHP
693   salld_set_swInfo(firstEngId, 0, 
694                    &txInst->destInfo,
695                    pScInfo, &txInst->swInfo, tagSize);
696   #else
697   /* Data packets enter PHP engine */
698   salld_set_swInfo(SALLD_CMDL_ENGINE_SRTP_AC_HPS1, 0, 
699                    &txInst->destInfo,
700                    pScInfo, &txInst->swInfo, 0);
701   #endif
702   /* Store the scBuf internally as offset to suppor multiprocess */
703   pScInfo->scBuf = (uint8_t*) sa_CONV_ADDR_TO_OFFSET(salldLObj.scPoolBaseAddr, pScInfo->scBuf);
704   
705   return (sa_ERR_OK);
706
708 /****************************************************************************
709  * FUNCTION PURPOSE: Data Mode Get SwInfo 
710  ****************************************************************************
711  * DESCRIPTION: Data Mode Get SwInfo
712  *
713  * int16_t  salld_data_mode_get_swInfo (
714  *   Sa_ChanHandle        handle      - SALLD channel identifier
715  *   uint16_t             dir         - packet directions
716  *   Sa_SWInfo_t         *pSwInfo)    - a pointer to swInfo
717  *
718  * Return values:  sa_ERR_OK
719  *                 sa_ERR_GEN
720  *                 sa_ERR_PARAMS
721  *                 sa_ERR_UNSUPPORTED
722  *
723  ***************************************************************************/
724 int16_t salld_data_mode_get_swInfo (void *salldInst, uint16_t dir, Sa_SWInfo_t* pChanSwInfo)
726   salldDataModeInst_t *inst = (salldDataModeInst_t *)salldInst;
727   int16_t ret = sa_ERR_OK;
728   
729   if (dir == sa_PKT_DIR_TO_NETWORK)
730   {
731     salldDataModeTxInst_t *txInst = (salldDataModeTxInst_t *) &inst->txInst;
732     memcpy(pChanSwInfo, &txInst->swInfo, sizeof(Sa_SWInfo_t));
733   }
734   else
735   {
736     ret = sa_ERR_PARAMS;
737   }
738   
739   return(ret);
742 /****************************************************************************
743  * Table PURPOSE:   Data Mode function call table 
744  ****************************************************************************
745  * DESCRIPTION:     The tables are used to link Data Mode functions to the 
746  *                  SALLD library if required 
747  *
748  ***************************************************************************/
749 Sa_ProtocolCallTbl_t Sa_callTblDataMode = 
751   sa_PT_NULL,
752   salld_data_mode_init,
753   salld_data_mode_control,
754   salld_data_mode_get_stats,
755   salld_data_mode_send_data,
756   salld_data_mode_receive_data,
757   salld_data_mode_close,
758   salld_data_mode_get_swInfo
759 };
760            
761    
762 /* Nothing past this point */