1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef DM_UA_TYPEDEFS_H 18 #define DM_UA_TYPEDEFS_H 19 20 /*================================================================================================== 21 22 Header Name: dm_ua_typedefs.h 23 24 General Description: This contains DMUA data type definitions. 25 26 ==================================================================================================*/ 27 28 #include "syncml_dm_data_types.h" 29 #include "smldtd.h" 30 #include "dmbuffer.h" 31 #include "dm_tree_class.H" 32 33 /*================================================================================================== 34 CONSTANTS 35 ==================================================================================================*/ 36 37 #define UINT16_TYPE_STR_SIZE_5 6 /* Array size for coverting a UINT16 number to a string */ 38 #define UINT32_TYPE_STR_SIZE_10 11 /* Array size for coverting a UINT32 number to a string */ 39 40 #define NUMBER_OF_WORKSPACE 2 /* Number of workspace for a session */ 41 #define WORKSPACE_NAME_LEN 30 /* String length of workspace name */ 42 #define MAX_BIN_NONCE_LEN 50 /* Maximum length of a binary decoded Nonce */ 43 #define MAX_BIN_VAL_LEN 50 /* Max length of a b64 decode bin array */ 44 45 #define DEFAULT_MESSAGE_ID "1" 46 #define DEFAULT_HDR_CMD_ID "0" 47 48 #define SERVER_RESYNC_NONCE "AAAAAA==" // Motorola, <e50324>, <12/08/09>, <ikmap-2156> / Nonce Resynchronization 49 //#define SERVER_RESYNC_NONCE "MTIzNDU=" // for Sprint HFA OMA DM 50 51 /*================================================================================================== 52 ENUMS 53 ==================================================================================================*/ 54 /* These enums are used when handling the AppNotify messages.*/ 55 enum 56 { 57 SYNCML_DM_NODE_ADD, 58 SYNCML_DM_NODE_DELETE, 59 SYNCML_DM_NODE_RENAME, 60 SYNCML_DM_NODE_INVALID 61 }; 62 typedef UINT8 SYNCML_DM_NODE_CHANGE_T; 63 64 /* These enums are used for the various Challenge types.*/ 65 enum 66 { 67 SYNCML_DM_CHAL_UNDEFINED = -1, 68 SYNCML_DM_CHAL_NONE = 0, 69 SYNCML_DM_CHAL_BASIC = 1, 70 SYNCML_DM_CHAL_MD5 = 2, 71 SYNCML_DM_CHAL_HMAC = 3 72 }; 73 typedef INT8 SYNCML_DM_CHAL_TYPE_T; 74 75 /* Type Defines */ 76 enum { 77 DM_COMMAND_INVALID = 0, 78 DM_COMMAND_ADD, 79 DM_COMMAND_ALERT, 80 DM_COMMAND_ATOMIC_START, 81 DM_COMMAND_ATOMIC_END, 82 DM_COMMAND_COPY, 83 DM_COMMAND_DELETE, 84 DM_COMMAND_EXEC, 85 DM_COMMAND_GET, 86 DM_COMMAND_MAP, 87 DM_COMMAND_PUT, 88 DM_COMMAND_RESULTS, 89 DM_COMMAND_SEARCH, 90 DM_COMMAND_SEQUENCE_START, 91 DM_COMMAND_SEQUENCE_END, 92 DM_COMMAND_STATUS, 93 DM_COMMAND_SYNC_START, 94 DM_COMMAND_SYNC_END, 95 DM_COMMAND_REPLACE, 96 DM_COMMAND_HEADER, 97 DM_COMMAND_BODY_END, 98 DM_COMMAND_COUNT 99 }; 100 typedef UINT8 DMCommandType; 101 102 /*================================================================================================== 103 TYPEDEFS 104 ==================================================================================================*/ 105 106 /* This structure is used to hold credential information. */ 107 class DMCredHeaders 108 { 109 public: 110 inline void clear() 111 { 112 m_oAlgorithm.clear(); 113 m_oUserName.clear(); 114 m_oMac.clear(); 115 } 116 117 inline BOOLEAN empty() const 118 { 119 return ( (m_oUserName.getSize() == 0 || m_oMac.getSize() == 0) ? TRUE : FALSE ); 120 } 121 122 inline BOOLEAN isCorrect() const 123 { 124 if ( m_oUserName.getSize() != 0 ) 125 { 126 if ( m_oMac.getSize() == 0 ) 127 return FALSE; 128 } 129 else 130 { 131 if ( m_oMac.getSize() != 0 ) 132 return FALSE; 133 } 134 return TRUE; 135 } 136 137 DMBuffer m_oAlgorithm; 138 DMBuffer m_oUserName; 139 DMBuffer m_oMac; 140 }; 141 142 143 144 typedef struct 145 { 146 UINT8 *pChalType; 147 UINT8 *pChalFormat; 148 UINT8 *pChalNonce; 149 } DM_CHALLENGE_T; 150 151 152 /* Added for Multiple Messages Support */ 153 struct SYNCML_DM_STATUS_DATA_T 154 { 155 DMString pCmdId; 156 DMString pCmdName; 157 DMString pSource; 158 DMString pTarget; 159 SYNCML_DM_RET_STATUS_T status; 160 DMStringVector responses; // alert requires additional parameters 161 BOOLEAN bValueSet; 162 BOOLEAN bInSequence; 163 164 SYNCML_DM_STATUS_DATA_T() { status = 0; bValueSet = FALSE; bInSequence = FALSE;} 165 SYNCML_DM_STATUS_DATA_T( const char* szCmd, const char* szCmdName, const char* szSource, 166 const char* szTarget, SYNCML_DM_RET_STATUS_T st, DMStringVector* pAdditionalData = NULL ){ 167 pCmdId = szCmd; 168 pCmdName = szCmdName; 169 pSource = szSource; 170 pTarget = szTarget; 171 status = st; 172 bValueSet = TRUE; 173 bInSequence = FALSE; 174 175 if ( pAdditionalData ) 176 responses = *pAdditionalData; 177 } 178 }; 179 180 struct SYNCML_DM_RESULT_VALUE { 181 enum {Enum_Result_Get, Enum_Result_GetStruct, Enum_Result_GetStructData, Enum_Result_GetTnds, Enum_Result_Exec}; 182 183 SmlResultsPtr_t _pGetExecResult; 184 SYNCML_DM_GET_ON_LIST_RET_DATA_T _oGetStructPos; // cached position for GetStruct 185 UINT8 _type; // see enum above 186 DMString _cmdRef; 187 DMString _msgID; 188 189 // methods 190 inline SYNCML_DM_RESULT_VALUE() 191 { 192 _type = 0; _pGetExecResult = NULL; 193 } 194 inline SYNCML_DM_RESULT_VALUE( UINT8 type, SmlResultsPtr_t pRes, const SYNCML_DM_GET_ON_LIST_RET_DATA_T& oData, const char* strCmdRef, const char* strMsgID ){ 195 _type = type; 196 _oGetStructPos = oData; 197 _pGetExecResult = pRes; 198 _cmdRef = strCmdRef; 199 _msgID = strMsgID; 200 } 201 }; 202 203 204 class DMProcessScriptSession; 205 class SYNCML_DM_BuildPackage; 206 207 struct SYNCML_DM_USER_DATA_T 208 { 209 enum {Enum_Alert_None, Enum_Alert_Cancel, Enum_Alert_No}; 210 211 // saved statuses 212 DMVector<UINT32> aStatuses; 213 DMVector<SYNCML_DM_RESULT_VALUE> aResults; 214 215 DMString pMsgRef; 216 SYNCML_DM_STATUS_DATA_T pAtomicStatus; // atomic command state 217 DMVector<SYNCML_DM_STATUS_DATA_T> oStatus; // atomic statuses (not built) 218 BOOLEAN rollback; // inside atomic and already rolled back 219 BOOLEAN sequenceFailed; 220 SYNCML_DM_ALERT_RES_T alertState; // alert state in atomic/sequence/document - 221 BOOLEAN bNonceGenerated; 222 DMProcessScriptSession *pSessionMng; 223 SYNCML_DM_BuildPackage * pPkgBuilder; 224 225 226 inline SYNCML_DM_USER_DATA_T() { 227 rollback = FALSE; 228 sequenceFailed = FALSE; 229 bNonceGenerated = FALSE; 230 pMsgRef = NULL; 231 alertState = SYNCML_DM_ALERT_NONE; 232 pSessionMng = NULL; 233 pPkgBuilder = NULL; 234 } 235 236 inline bool IsCommandSkipped() const 237 { 238 return ( alertState == SYNCML_DM_ALERT_CANCEL || 239 ( ((pAtomicStatus.bValueSet || pAtomicStatus.bInSequence) && 240 (rollback || alertState == SYNCML_DM_ALERT_NO)) || 241 (pAtomicStatus.bInSequence && sequenceFailed))); 242 } 243 inline void EndAtomic() { 244 pAtomicStatus.bValueSet = FALSE; 245 rollback = FALSE; 246 oStatus.clear(); 247 248 if ( alertState != SYNCML_DM_ALERT_CANCEL ) 249 alertState = SYNCML_DM_ALERT_NONE; 250 } 251 252 inline BOOLEAN IsSequence() 253 { 254 return pAtomicStatus.bInSequence; 255 } 256 257 inline void StartSequence() 258 { 259 pAtomicStatus.bInSequence = TRUE; 260 } 261 inline void EndSequence() 262 { 263 pAtomicStatus.bInSequence = FALSE; 264 sequenceFailed = FALSE; 265 266 if ( alertState != Enum_Alert_Cancel ) 267 alertState = Enum_Alert_None; 268 } 269 }; 270 271 #endif /* DM_UA_TYPEDEFS_H */ 272