Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "CSFLog.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "CC_Common.h" |
michael@0 | 8 | #include "csf_common.h" |
michael@0 | 9 | #ifdef WIN32 |
michael@0 | 10 | #include <windows.h> |
michael@0 | 11 | #else |
michael@0 | 12 | #ifdef LINUX |
michael@0 | 13 | // for platGetIPAddr |
michael@0 | 14 | #include <sys/ioctl.h> |
michael@0 | 15 | #include <sys/types.h> |
michael@0 | 16 | #include <arpa/inet.h> |
michael@0 | 17 | #include <net/if.h> |
michael@0 | 18 | #include <fcntl.h> |
michael@0 | 19 | #endif |
michael@0 | 20 | #endif |
michael@0 | 21 | |
michael@0 | 22 | #include "cpr_string.h" |
michael@0 | 23 | |
michael@0 | 24 | static const char* logTag = "sipcc"; |
michael@0 | 25 | |
michael@0 | 26 | extern "C" |
michael@0 | 27 | { |
michael@0 | 28 | #include "plat_api.h" |
michael@0 | 29 | #include <stdarg.h> |
michael@0 | 30 | |
michael@0 | 31 | |
michael@0 | 32 | void NotifyStateChange (cc_callid_t callid, int32_t state) { |
michael@0 | 33 | //Don't need anything here. |
michael@0 | 34 | //Call state change are notified to us via SIPCC "high level" API |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | #ifndef OSX |
michael@0 | 38 | /** |
michael@0 | 39 | * platGetFeatureAllowed |
michael@0 | 40 | * |
michael@0 | 41 | * Get whether the feature is allowed |
michael@0 | 42 | * |
michael@0 | 43 | * @param featureId - sis feature id |
michael@0 | 44 | * |
michael@0 | 45 | * @return 1 - allowed, 0 - not allowed |
michael@0 | 46 | * |
michael@0 | 47 | */ |
michael@0 | 48 | int platGetFeatureAllowed(cc_sis_feature_id_e featureId) { |
michael@0 | 49 | return 1; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * Set the Status message for failure reasons |
michael@0 | 54 | * @param char *msg |
michael@0 | 55 | * @return void |
michael@0 | 56 | */ |
michael@0 | 57 | void platSetStatusMessage(char *msg) { |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | /** |
michael@0 | 61 | * Sets the time based on Date header in 200 OK from REGISTER request |
michael@0 | 62 | * @param void |
michael@0 | 63 | * @return void |
michael@0 | 64 | */ |
michael@0 | 65 | void platSetCucmRegTime (void) { |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | /** |
michael@0 | 69 | * Enable / disable speaker |
michael@0 | 70 | * |
michael@0 | 71 | * @param[in] state - true -> enable speaker, false -> disable speaker |
michael@0 | 72 | * |
michael@0 | 73 | * @return void |
michael@0 | 74 | */ |
michael@0 | 75 | extern "C" void platSetSpeakerMode(cc_boolean state) { |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | /** |
michael@0 | 79 | * Get the status (on/off) of the audio device |
michael@0 | 80 | * |
michael@0 | 81 | * @param[in] device_type - headset or speaker (see vcm_audio_device_t) |
michael@0 | 82 | * |
michael@0 | 83 | * @return 1 -> On, 0 -> off, ERROR -> unknown (error) |
michael@0 | 84 | */ |
michael@0 | 85 | int platGetAudioDeviceStatus(plat_audio_device_t device_type) { |
michael@0 | 86 | //Tell SIPCC what the current audio path is by return 1 for one of either: headset or speaker. |
michael@0 | 87 | return 1; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Check if the speaker or headset is enabled. |
michael@0 | 92 | * |
michael@0 | 93 | * @return boolean if the speaker or headset is enabled, returns true. |
michael@0 | 94 | */ |
michael@0 | 95 | boolean platGetSpeakerHeadsetMode() { |
michael@0 | 96 | return TRUE; |
michael@0 | 97 | } |
michael@0 | 98 | #endif |
michael@0 | 99 | |
michael@0 | 100 | /** |
michael@0 | 101 | * Provides the local MAC address |
michael@0 | 102 | * |
michael@0 | 103 | * @param *maddr the pointer to the string holding MAC address |
michael@0 | 104 | * in the MAC address format after converting from string format. |
michael@0 | 105 | * @return void |
michael@0 | 106 | */ |
michael@0 | 107 | void platGetMacAddr(char *maddr) { |
michael@0 | 108 | //Strictly speaking the code using this is not treating this as a string. |
michael@0 | 109 | //It's taking the first 6 bytes out of the buffer, and printing these |
michael@0 | 110 | //directly, so it's not enough to just make the first byte '\0' need |
michael@0 | 111 | //to set all of the bytes in range 0-5 equal to '\0'. |
michael@0 | 112 | //Have to assume here that the buffer is big enough. |
michael@0 | 113 | for (int i=0; i<6; i++) |
michael@0 | 114 | { |
michael@0 | 115 | *(maddr+i) = '\0'; |
michael@0 | 116 | } |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | #ifndef OSX |
michael@0 | 120 | /** |
michael@0 | 121 | * Called by the thread to initialize any thread specific data |
michael@0 | 122 | * once the thread is created. |
michael@0 | 123 | * |
michael@0 | 124 | * @param[in] tname thread name |
michael@0 | 125 | * |
michael@0 | 126 | * @return 0 - SUCCESS |
michael@0 | 127 | * -1 - FAILURE |
michael@0 | 128 | */ |
michael@0 | 129 | int platThreadInit(char * tname) { |
michael@0 | 130 | return 0; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | /** |
michael@0 | 134 | * The initial initialization function for any platform related |
michael@0 | 135 | * modules |
michael@0 | 136 | * |
michael@0 | 137 | * |
michael@0 | 138 | * @return 0 - SUCCESS |
michael@0 | 139 | * -1 - FAILURE |
michael@0 | 140 | */ |
michael@0 | 141 | int platInit() { |
michael@0 | 142 | return 0; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | /** |
michael@0 | 146 | * The initial initialization function for the debugging/logging |
michael@0 | 147 | * modules |
michael@0 | 148 | * |
michael@0 | 149 | */ |
michael@0 | 150 | void debugInit() { |
michael@0 | 151 | return ; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * Add cc control classifier |
michael@0 | 156 | * |
michael@0 | 157 | * Called by SIP stack to specify addresses and ports that will be used for call control |
michael@0 | 158 | * |
michael@0 | 159 | * @param[in] myIPAddr - phone local interface IP Address |
michael@0 | 160 | * @param[in] myPort - phone local interface Port |
michael@0 | 161 | * @param[in] cucm1IPAddr - CUCM 1 IP Address |
michael@0 | 162 | * @param[in] cucm1Port - CUCM 1 Port |
michael@0 | 163 | * @param[in] cucm2IPAddr - CUCM 2 IP Address |
michael@0 | 164 | * @param[in] cucm2Port - CUCM 2 Port |
michael@0 | 165 | * @param[in] cucm3IPAddr - CUCM 3 IP Address |
michael@0 | 166 | * @param[in] cucm3Port - CUCM 3 Port |
michael@0 | 167 | * @param[in] protocol - CC_IPPROTO_UDP or CC_IP_PROTO_TCP |
michael@0 | 168 | * |
michael@0 | 169 | * @note : Needed only if using WiFi. If not using Wifi please provide a stub |
michael@0 | 170 | */ |
michael@0 | 171 | void platAddCallControlClassifiers(unsigned long myIPAddr, unsigned short myPort, |
michael@0 | 172 | unsigned long cucm1IPAddr, unsigned short cucm1Port, |
michael@0 | 173 | unsigned long cucm2IPAddr, unsigned short cucm2Port, |
michael@0 | 174 | unsigned long cucm3IPAddr, unsigned short cucm3Port, |
michael@0 | 175 | unsigned char protocol) { |
michael@0 | 176 | //Needed only if using WiFi. If not using Wifi please provide a stub |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | /** |
michael@0 | 180 | * Remove cc control classifier. |
michael@0 | 181 | * |
michael@0 | 182 | * Undo platAddCallControlClassifiers |
michael@0 | 183 | */ |
michael@0 | 184 | void platRemoveCallControlClassifiers() { |
michael@0 | 185 | //Needed only if using WiFi. If not using Wifi please provide a stub |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | /** |
michael@0 | 189 | * Set ip address mode |
michael@0 | 190 | * e.g. |
michael@0 | 191 | * |
michael@0 | 192 | */ |
michael@0 | 193 | cpr_ip_mode_e platGetIpAddressMode() { |
michael@0 | 194 | return CPR_IP_MODE_IPV4; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * Tell whether wifi is supported and active |
michael@0 | 199 | * |
michael@0 | 200 | * @return boolean wether WLAN is active or not |
michael@0 | 201 | */ |
michael@0 | 202 | cc_boolean platWlanISActive() { |
michael@0 | 203 | return FALSE; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | /** |
michael@0 | 207 | * Check if the network interface changed. |
michael@0 | 208 | * |
michael@0 | 209 | * @return boolean returns TRUE if the network interface has changed |
michael@0 | 210 | * |
michael@0 | 211 | * @note Most common case is for softphone clients where if a PC is |
michael@0 | 212 | * undocked the network interface changes from wired to wireless. |
michael@0 | 213 | */ |
michael@0 | 214 | boolean platIsNetworkInterfaceChanged() { |
michael@0 | 215 | //We're OK with this |
michael@0 | 216 | return FALSE; |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | /** |
michael@0 | 220 | * Get active phone load name |
michael@0 | 221 | * |
michael@0 | 222 | * Returns the phone images in the active and inactive partitions |
michael@0 | 223 | * The phone reports these phone loads to CUCM for display on the Admin page |
michael@0 | 224 | * |
michael@0 | 225 | * @param[in] image_a : Populate the image name from partition a |
michael@0 | 226 | * @param[in] image_b : Populate the image name from partition b |
michael@0 | 227 | * @param[in] len : Length of the pointers for image_a and image_b |
michael@0 | 228 | * @return 1 - image_a is active. |
michael@0 | 229 | * Anything other than 1 - image_b is active |
michael@0 | 230 | */ |
michael@0 | 231 | int platGetActiveInactivePhoneLoadName(char * image_a, char * image_b, int len) { |
michael@0 | 232 | if (image_a != nullptr) |
michael@0 | 233 | { |
michael@0 | 234 | sstrncpy(image_a, "image_a", len); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | if (image_b != nullptr) |
michael@0 | 238 | { |
michael@0 | 239 | sstrncpy(image_b, "image_b", len); |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | return 1; |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | /** |
michael@0 | 246 | * Get or Set user defined phrases |
michael@0 | 247 | * @param index the phrase index, see |
michael@0 | 248 | * @param phrase the return phrase holder |
michael@0 | 249 | * @param len the input length to cap the maximum value |
michael@0 | 250 | * @return SUCCESS or FAILURE |
michael@0 | 251 | */ |
michael@0 | 252 | int platGetPhraseText(int index, char* phrase, unsigned int len) { |
michael@0 | 253 | //Need to copy something into "phrase" as this is used as a prefix |
michael@0 | 254 | //in a starts with comparison (use strncmp) that will match against |
michael@0 | 255 | //any string if the prefix is empty. Also in some places an |
michael@0 | 256 | //uninitialized buffer is passed in as "phrase", so if we don't |
michael@0 | 257 | //do something then SIPCC will go on the use the uninitialized |
michael@0 | 258 | //buffer. |
michael@0 | 259 | |
michael@0 | 260 | if (phrase == nullptr) |
michael@0 | 261 | { |
michael@0 | 262 | return CC_FAILURE; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | sstrncpy(phrase, "?????", len); |
michael@0 | 266 | |
michael@0 | 267 | return (int) CC_SUCCESS; |
michael@0 | 268 | } |
michael@0 | 269 | |
michael@0 | 270 | /** |
michael@0 | 271 | * Get the unregistration reason code. |
michael@0 | 272 | * @return reason code for unregistration, see the definition. |
michael@0 | 273 | */ |
michael@0 | 274 | int platGetUnregReason() { |
michael@0 | 275 | return 0; |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | /** |
michael@0 | 279 | * Set the unregistration reason |
michael@0 | 280 | * @param reason see the unregister reason definitions. |
michael@0 | 281 | * @return void |
michael@0 | 282 | */ |
michael@0 | 283 | void platSetUnregReason(int reason) { |
michael@0 | 284 | //We may need to persist this for CUCM. WHen we restart next time call to platGetUnregReason above tells CUCM what why we unregistered last time. |
michael@0 | 285 | typedef struct _unRegRreasonEnumPair { |
michael@0 | 286 | int reason; |
michael@0 | 287 | const char * pReasonStr; |
michael@0 | 288 | } unRegRreasonEnumPair; |
michael@0 | 289 | |
michael@0 | 290 | static unRegRreasonEnumPair unRegReasons[] = { |
michael@0 | 291 | { CC_UNREG_REASON_UNSPECIFIED, "CC_UNREG_REASON_UNSPECIFIED" }, |
michael@0 | 292 | { CC_UNREG_REASON_TCP_TIMEOUT, "CC_UNREG_REASON_TCP_TIMEOUT" }, |
michael@0 | 293 | { CC_UNREG_REASON_CM_RESET_TCP, "CC_UNREG_REASON_CM_RESET_TCP" }, |
michael@0 | 294 | { CC_UNREG_REASON_CM_ABORTED_TCP, "CC_UNREG_REASON_CM_ABORTED_TCP" }, |
michael@0 | 295 | { CC_UNREG_REASON_CM_CLOSED_TCP, "C_UNREG_REASON_CM_CLOSED_TCP" }, |
michael@0 | 296 | { CC_UNREG_REASON_REG_TIMEOUT, "CC_UNREG_REASON_REG_TIMEOUT" }, |
michael@0 | 297 | { CC_UNREG_REASON_FALLBACK, "CC_UNREG_REASON_FALLBACK" }, |
michael@0 | 298 | { CC_UNREG_REASON_PHONE_KEYPAD, "CC_UNREG_REASON_PHONE_KEYPAD" }, |
michael@0 | 299 | { CC_UNREG_REASON_RESET_RESET, "CC_UNREG_REASON_RESET_RESET" }, |
michael@0 | 300 | { CC_UNREG_REASON_RESET_RESTART, "CC_UNREG_REASON_RESET_RESTART" }, |
michael@0 | 301 | { CC_UNREG_REASON_PHONE_REG_REJ, "CC_UNREG_REASON_PHONE_REG_REJ" }, |
michael@0 | 302 | { CC_UNREG_REASON_PHONE_INITIALIZED, "CC_UNREG_REASON_PHONE_INITIALIZED" }, |
michael@0 | 303 | { CC_UNREG_REASON_VOICE_VLAN_CHANGED, "CC_UNREG_REASON_VOICE_VLAN_CHANGED" }, |
michael@0 | 304 | { CC_UNREG_REASON_POWER_SAVE_PLUS, "CC_UNREG_REASON_POWER_SAVE_PLUS" }, |
michael@0 | 305 | { CC_UNREG_REASON_VERSION_STAMP_MISMATCH, "CC_UNREG_REASON_VERSION_STAMP_MISMATCH" }, |
michael@0 | 306 | { CC_UNREG_REASON_VERSION_STAMP_MISMATCH_CONFIG, "CC_UNREG_REASON_VERSION_STAMP_MISMATCH_CONFIG" }, |
michael@0 | 307 | { CC_UNREG_REASON_VERSION_STAMP_MISMATCH_SOFTKEY, "CC_UNREG_REASON_VERSION_STAMP_MISMATCH_SOFTKEY" }, |
michael@0 | 308 | { CC_UNREG_REASON_VERSION_STAMP_MISMATCH_DIALPLAN, "CC_UNREG_REASON_VERSION_STAMP_MISMATCH_DIALPLAN" }, |
michael@0 | 309 | { CC_UNREG_REASON_APPLY_CONFIG_RESTART, "CC_UNREG_REASON_APPLY_CONFIG_RESTART" }, |
michael@0 | 310 | { CC_UNREG_REASON_CONFIG_RETRY_RESTART, "CC_UNREG_REASON_CONFIG_RETRY_RESTART" }, |
michael@0 | 311 | { CC_UNREG_REASON_TLS_ERROR, "CC_UNREG_REASON_TLS_ERROR" }, |
michael@0 | 312 | { CC_UNREG_REASON_RESET_TO_INACTIVE_PARTITION, "CC_UNREG_REASON_RESET_TO_INACTIVE_PARTITION" }, |
michael@0 | 313 | { CC_UNREG_REASON_VPN_CONNECTIVITY_LOST, "CC_UNREG_REASON_VPN_CONNECTIVITY_LOST" } |
michael@0 | 314 | }; |
michael@0 | 315 | |
michael@0 | 316 | for (int i=0; i< (int) csf_countof(unRegReasons); i++) |
michael@0 | 317 | { |
michael@0 | 318 | unRegRreasonEnumPair * pCurrentUnRegReasonPair = &unRegReasons[i]; |
michael@0 | 319 | |
michael@0 | 320 | if (pCurrentUnRegReasonPair->reason == reason) |
michael@0 | 321 | { |
michael@0 | 322 | CSFLogDebug( logTag, "platSetUnregReason(%s)", pCurrentUnRegReasonPair->pReasonStr); |
michael@0 | 323 | return; |
michael@0 | 324 | } |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | CSFLogError( logTag, "Unknown reason code (%d) passed to platSetUnregReason()", reason); |
michael@0 | 328 | } |
michael@0 | 329 | |
michael@0 | 330 | |
michael@0 | 331 | #endif |
michael@0 | 332 | |
michael@0 | 333 | #ifndef OSX |
michael@0 | 334 | /** |
michael@0 | 335 | * Set the kpml value for application. |
michael@0 | 336 | * @param kpml_config the kpml value |
michael@0 | 337 | * @return void |
michael@0 | 338 | */ |
michael@0 | 339 | void platSetKPMLConfig(cc_kpml_config_t kpml_config) { |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | /** |
michael@0 | 343 | * Check if a line has active MWI status |
michael@0 | 344 | * @param line |
michael@0 | 345 | * @return boolean |
michael@0 | 346 | */ |
michael@0 | 347 | boolean platGetMWIStatus(cc_lineid_t line) { |
michael@0 | 348 | return TRUE; |
michael@0 | 349 | } |
michael@0 | 350 | |
michael@0 | 351 | |
michael@0 | 352 | /** |
michael@0 | 353 | * Secure Socket API's. |
michael@0 | 354 | * The pSIPCC expects the following Secure Socket APIs to be implemented in the |
michael@0 | 355 | * vendor porting layer. |
michael@0 | 356 | */ |
michael@0 | 357 | |
michael@0 | 358 | /** |
michael@0 | 359 | * platSecIsServerSecure |
michael@0 | 360 | * |
michael@0 | 361 | * @brief Lookup the secure status of the server |
michael@0 | 362 | * |
michael@0 | 363 | * This function looks at the the CCM server type by using the security library |
michael@0 | 364 | * and returns appropriate indication to the pSIPCC. |
michael@0 | 365 | * |
michael@0 | 366 | * |
michael@0 | 367 | * @return Server is security enabled or not |
michael@0 | 368 | * PLAT_SOCK_SECURE or PLAT_SOCK_NONSECURE |
michael@0 | 369 | * |
michael@0 | 370 | * @note This API maps to the following HandyIron API: |
michael@0 | 371 | * int secIsServerSecure(SecServerType type) where type should be SRVR_TYPE_CCM |
michael@0 | 372 | */ |
michael@0 | 373 | plat_soc_status_e platSecIsServerSecure(void) { |
michael@0 | 374 | return PLAT_SOCK_NONSECURE; |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | |
michael@0 | 378 | /** |
michael@0 | 379 | * platSecSocConnect |
michael@0 | 380 | * @brief Securely connect to a remote server |
michael@0 | 381 | * |
michael@0 | 382 | * This function uses the security library APIs to connect to a remote server. |
michael@0 | 383 | * @param[in] host server addr |
michael@0 | 384 | * @param[in] port port number |
michael@0 | 385 | * @param[in] ipMode IP mode to indicate v6, v4 or both |
michael@0 | 386 | * @param[in] mode blocking connect or not |
michael@0 | 387 | * FALSE: non-blocking; TRUE: blocking |
michael@0 | 388 | * @param[in] tos TOS value |
michael@0 | 389 | * @param[in] connectionType Are we talking to Call-Agent |
michael@0 | 390 | * @param[in] connectionMode The mode of the connection |
michael@0 | 391 | * (Authenticated/Encrypted) |
michael@0 | 392 | * @param[out] localPort local port used for the connection |
michael@0 | 393 | * |
michael@0 | 394 | * @return client socket descriptor |
michael@0 | 395 | * >=0: connected or in progress |
michael@0 | 396 | * INVALID SOCKET: failed |
michael@0 | 397 | * |
michael@0 | 398 | * @pre (hostAndPort not_eq nullptr) |
michael@0 | 399 | * @pre (localPort not_eq nullptr) |
michael@0 | 400 | * |
michael@0 | 401 | * @note localPort is undefined when the return value is INVALID_SOCKET |
michael@0 | 402 | * |
michael@0 | 403 | * @note This API maps to the HandyIron APIs as follows: |
michael@0 | 404 | * If mode == TRUE (blocking): |
michael@0 | 405 | * int secEstablishSecureConnection(const char* serverAddr, *uint32_t port, secConnectionType type) |
michael@0 | 406 | * @li ipMode is UNUSED |
michael@0 | 407 | * @li "host" maps to "serverAddr", "connectionType" maps to "type" |
michael@0 | 408 | * @li localPort is passed in as 0 |
michael@0 | 409 | * If mode == FALSE (non-blocking): |
michael@0 | 410 | * int secConnect(const char* serverAddr, uint32_t port, *secConnectionType type, uint32_t localPort) |
michael@0 | 411 | * @li ipMode is UNUSED |
michael@0 | 412 | * @li "host" maps to "serverAddr", "connectionType" maps to "type" |
michael@0 | 413 | * |
michael@0 | 414 | * @note The implementation should use the "setsockopt" to set the "tos" value passed |
michael@0 | 415 | * in this API on the created socket. |
michael@0 | 416 | * |
michael@0 | 417 | */ |
michael@0 | 418 | cpr_socket_t |
michael@0 | 419 | platSecSocConnect (char *host, |
michael@0 | 420 | int port, |
michael@0 | 421 | int ipMode, |
michael@0 | 422 | boolean mode, |
michael@0 | 423 | unsigned int tos, |
michael@0 | 424 | plat_soc_connect_mode_e connectionMode, |
michael@0 | 425 | uint16_t *localPort) { |
michael@0 | 426 | return 0; |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | /** |
michael@0 | 430 | * platSecSockIsConnected |
michael@0 | 431 | * Determine the status of a secure connection that was initiated |
michael@0 | 432 | * in non-blocking mode |
michael@0 | 433 | * |
michael@0 | 434 | * @param[in] sock socket descriptor |
michael@0 | 435 | * |
michael@0 | 436 | * @return connection status |
michael@0 | 437 | * @li connection complete: PLAT_SOCK_CONN_OK |
michael@0 | 438 | * @li connection waiting: PLAT_SOCK_CONN_WAITING |
michael@0 | 439 | * @li connection failed: PLAT_SOCK_CONN_FAILED |
michael@0 | 440 | * |
michael@0 | 441 | * @note This API maps to the following HandyIron API: |
michael@0 | 442 | * int secIsConnectionReady (int connDesc) |
michael@0 | 443 | * The "sock" is the connection descriptor. |
michael@0 | 444 | */ |
michael@0 | 445 | plat_soc_connect_status_e platSecSockIsConnected (cpr_socket_t sock) { |
michael@0 | 446 | return PLAT_SOCK_CONN_OK; |
michael@0 | 447 | } |
michael@0 | 448 | #endif //#endif !OSX |
michael@0 | 449 | |
michael@0 | 450 | /** |
michael@0 | 451 | * platGenerateCryptoRand |
michael@0 | 452 | * @brief Generates a Random Number |
michael@0 | 453 | * |
michael@0 | 454 | * Generate crypto graphically random number for a desired length. |
michael@0 | 455 | * The function is expected to be much slower than the cpr_rand(). |
michael@0 | 456 | * This function should be used when good random number is needed |
michael@0 | 457 | * such as random number that to be used for SRTP key for an example. |
michael@0 | 458 | * |
michael@0 | 459 | * @param[in] buf - pointer to the buffer to store the result of random |
michael@0 | 460 | * bytes requested. |
michael@0 | 461 | * @param[in] len - pointer to the length of the desired random bytes. |
michael@0 | 462 | * When calling the function, the integer's value |
michael@0 | 463 | * should be set to the desired number of random |
michael@0 | 464 | * bytes ('buf' should be of at least this size). |
michael@0 | 465 | * upon success, its value will be set to the |
michael@0 | 466 | * actual number of random bytes being returned. |
michael@0 | 467 | * (realistically, there is a maximum number of |
michael@0 | 468 | * random bytes that can be returned at a time. |
michael@0 | 469 | * if the caller request more than that, the |
michael@0 | 470 | * 'len' will indicate how many bytes are actually being |
michael@0 | 471 | * returned) on failure, its value will be set to 0. |
michael@0 | 472 | * |
michael@0 | 473 | * @return |
michael@0 | 474 | * 1 - success. |
michael@0 | 475 | * 0 - fail. |
michael@0 | 476 | * |
michael@0 | 477 | * @note The intent of this function is to generate a cryptographically strong |
michael@0 | 478 | * random number. Vendors can map this to HandyIron or OpenSSL random number |
michael@0 | 479 | * generation functions. |
michael@0 | 480 | * |
michael@0 | 481 | * @note This API maps to the following HandyIron API: |
michael@0 | 482 | * int secGetRandomData(uint8_t *buf, uint32_t size). Also note that a |
michael@0 | 483 | * "secAddEntropy(...)" may be required the first time to feed entropy data to |
michael@0 | 484 | * the random number generator. |
michael@0 | 485 | */ |
michael@0 | 486 | #ifdef LINUX |
michael@0 | 487 | int platGenerateCryptoRand(uint8_t *buf, int *len) { |
michael@0 | 488 | int fd; |
michael@0 | 489 | int rc = 0; |
michael@0 | 490 | ssize_t s; |
michael@0 | 491 | |
michael@0 | 492 | if ((fd = open("/dev/urandom", O_RDONLY)) == -1) { |
michael@0 | 493 | CSFLogDebug( logTag, "Failed to open prng driver"); |
michael@0 | 494 | return 0; |
michael@0 | 495 | } |
michael@0 | 496 | |
michael@0 | 497 | /* |
michael@0 | 498 | * Try to read the given amount of bytes from the PRNG device. We do not |
michael@0 | 499 | * handle short reads but just return the number of bytes read from the |
michael@0 | 500 | * device. The caller has to manage this. |
michael@0 | 501 | * E.g. gsmsdp_generate_key() in core/gsm/gsm_sdp_crypto.c |
michael@0 | 502 | */ |
michael@0 | 503 | |
michael@0 | 504 | s = read(fd, buf, (size_t) *len); |
michael@0 | 505 | |
michael@0 | 506 | if (s > 0) { |
michael@0 | 507 | *len = s; |
michael@0 | 508 | rc = 1; /* Success */ |
michael@0 | 509 | } else { |
michael@0 | 510 | *len = 0; |
michael@0 | 511 | rc = 0; /* Failure */ |
michael@0 | 512 | } |
michael@0 | 513 | |
michael@0 | 514 | |
michael@0 | 515 | (void) close(fd); |
michael@0 | 516 | return rc; |
michael@0 | 517 | } |
michael@0 | 518 | #else |
michael@0 | 519 | int platGenerateCryptoRand(uint8_t *buf, int *len) { |
michael@0 | 520 | return 0; |
michael@0 | 521 | } |
michael@0 | 522 | #endif//!LINUX |
michael@0 | 523 | |
michael@0 | 524 | #ifndef OSX |
michael@0 | 525 | |
michael@0 | 526 | /* |
michael@0 | 527 | <Umesh> The version is to regulate certain features like Join, which are added in later releases. |
michael@0 | 528 | This is exchanged during registration with CUCM. It is a sheer luck that join may be working in some cases. |
michael@0 | 529 | In this case Set API you have to store each of those API and return the same value in get. |
michael@0 | 530 | |
michael@0 | 531 | We can go over all platform API’ and see which one are mandatory, we can do this in an email or in a meeting. |
michael@0 | 532 | Please send out list methods for which you need clarification. |
michael@0 | 533 | */ |
michael@0 | 534 | static cc_uint32_t majorSIS=1, minorSIS=0, addtnlSIS =0; |
michael@0 | 535 | static char sis_ver_name[CC_MAX_LEN_REQ_SUPP_PARAM_CISCO_SISTAG] = {0}; |
michael@0 | 536 | |
michael@0 | 537 | /** |
michael@0 | 538 | * Sets the SIS protocol version |
michael@0 | 539 | * |
michael@0 | 540 | * @param a - major version |
michael@0 | 541 | * @param b - minor version |
michael@0 | 542 | * @param c - additional version information |
michael@0 | 543 | * @param name - version name |
michael@0 | 544 | * |
michael@0 | 545 | * @return void |
michael@0 | 546 | * @note the platform should store this information and provide it when asked via the platGetSISProtocolVer() |
michael@0 | 547 | */ |
michael@0 | 548 | void platSetSISProtocolVer(cc_uint32_t a, cc_uint32_t b, cc_uint32_t c, char* name) { |
michael@0 | 549 | majorSIS = a; |
michael@0 | 550 | minorSIS = b; |
michael@0 | 551 | addtnlSIS = c; |
michael@0 | 552 | |
michael@0 | 553 | if (name) { |
michael@0 | 554 | sstrncpy(sis_ver_name, name, csf_countof(sis_ver_name)); |
michael@0 | 555 | } else { |
michael@0 | 556 | *sis_ver_name = '\0'; |
michael@0 | 557 | } |
michael@0 | 558 | } |
michael@0 | 559 | |
michael@0 | 560 | /** |
michael@0 | 561 | * Provides the SIS protocol version |
michael@0 | 562 | * |
michael@0 | 563 | * @param *a pointer to fill in the major version |
michael@0 | 564 | * @param *b pointer to fill in the minor version |
michael@0 | 565 | * @param *c pointer to fill in the additonal version |
michael@0 | 566 | * @param *name pointer to fill in the version name |
michael@0 | 567 | * |
michael@0 | 568 | * @return void |
michael@0 | 569 | */ |
michael@0 | 570 | void |
michael@0 | 571 | platGetSISProtocolVer (cc_uint32_t *a, cc_uint32_t *b, cc_uint32_t *c, char* name) { |
michael@0 | 572 | |
michael@0 | 573 | if (a != nullptr) |
michael@0 | 574 | { |
michael@0 | 575 | *a = majorSIS; |
michael@0 | 576 | } |
michael@0 | 577 | |
michael@0 | 578 | if (b != nullptr) |
michael@0 | 579 | { |
michael@0 | 580 | *b = minorSIS; |
michael@0 | 581 | } |
michael@0 | 582 | |
michael@0 | 583 | if (c != nullptr) |
michael@0 | 584 | { |
michael@0 | 585 | *c = addtnlSIS; |
michael@0 | 586 | } |
michael@0 | 587 | |
michael@0 | 588 | if (name != nullptr) |
michael@0 | 589 | { |
michael@0 | 590 | sstrncpy(name, sis_ver_name, CC_MAX_LEN_REQ_SUPP_PARAM_CISCO_SISTAG); |
michael@0 | 591 | } |
michael@0 | 592 | |
michael@0 | 593 | return; |
michael@0 | 594 | } |
michael@0 | 595 | |
michael@0 | 596 | void debug_bind_keyword(const char *cmd, int32_t *flag_ptr) { |
michael@0 | 597 | return; |
michael@0 | 598 | } |
michael@0 | 599 | |
michael@0 | 600 | void debugif_add_keyword(const char *x, const char *y) { |
michael@0 | 601 | return; |
michael@0 | 602 | } |
michael@0 | 603 | #endif |
michael@0 | 604 | |
michael@0 | 605 | // Keep this when we are building the sipcc library without it, so that we capture logging |
michael@0 | 606 | int debugif_printf(const char *_format, ...) { |
michael@0 | 607 | va_list ap; |
michael@0 | 608 | va_start(ap, _format); |
michael@0 | 609 | CSFLogDebugV( logTag, _format, ap); |
michael@0 | 610 | va_end(ap); |
michael@0 | 611 | return 1; // Fake a "happy" return value. |
michael@0 | 612 | } |
michael@0 | 613 | |
michael@0 | 614 | } |
michael@0 | 615 |