| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "asterisk.h" |
| 24 |
#include "asterisk/lock.h" |
| 25 |
#include "asterisk/netsock2.h" |
| 26 |
|
| 27 |
#include "ooGkClient.h" |
| 28 |
#include "ootypes.h" |
| 29 |
#include "ootrace.h" |
| 30 |
#include "ooports.h" |
| 31 |
#include "ooasn1.h" |
| 32 |
#include "oochannels.h" |
| 33 |
#include "printHandler.h" |
| 34 |
#include "ooCalls.h" |
| 35 |
#include "H323-MESSAGES.h" |
| 36 |
#include "ooDateTime.h" |
| 37 |
#include "ooq931.h" |
| 38 |
#include "ooh323.h" |
| 39 |
#include "ooh323ep.h" |
| 40 |
#include "ooTimer.h" |
| 41 |
#include "ooSocket.h" |
| 42 |
#include "ooUtils.h" |
| 43 |
|
| 44 |
|
| 45 |
extern OOH323EndPoint gH323ep; |
| 46 |
|
| 47 |
static ASN1OBJID gProtocolID = { |
| 48 |
6, { 0, 0, 8, 2250, 0, 4 } |
| 49 |
}; |
| 50 |
|
| 51 |
int ooGkClientInit(enum RasGatekeeperMode eGkMode, |
| 52 |
char *szGkAddr, char *szRasAddr, int iGkPort ) |
| 53 |
{ |
| 54 |
ooGkClient *pGkClient=NULL; |
| 55 |
OOInterface *cur=NULL; |
| 56 |
pGkClient = (ooGkClient*) |
| 57 |
memAlloc(&gH323ep.ctxt, sizeof(ooGkClient)); |
| 58 |
if(!pGkClient) |
| 59 |
{ |
| 60 |
OOTRACEERR1("Error: Failed to allocate memory to Gatekeeper Client.\n"); |
| 61 |
return OO_FAILED; |
| 62 |
} |
| 63 |
|
| 64 |
memset(pGkClient, 0, sizeof(ooGkClient)); |
| 65 |
ast_mutex_init(&pGkClient->Lock); |
| 66 |
gH323ep.gkClient = pGkClient; |
| 67 |
initContext(&(pGkClient->ctxt)); |
| 68 |
initContext(&(pGkClient->msgCtxt)); |
| 69 |
pGkClient->rrqRetries = 0; |
| 70 |
pGkClient->grqRetries = 0; |
| 71 |
|
| 72 |
if (szRasAddr && *szRasAddr) { |
| 73 |
strcpy(pGkClient->localRASIP, szRasAddr); |
| 74 |
} else { |
| 75 |
strcpy(pGkClient->localRASIP, gH323ep.signallingIP); |
| 76 |
} |
| 77 |
#ifndef _WIN32 |
| 78 |
if(!strcmp(pGkClient->localRASIP, "0.0.0.0") || |
| 79 |
!strcmp(pGkClient->localRASIP, "127.0.0.1")) |
| 80 |
{ |
| 81 |
if(!gH323ep.ifList) |
| 82 |
{ |
| 83 |
if(ooSocketGetInterfaceList(&gH323ep.ctxt, &gH323ep.ifList)!= ASN_OK) |
| 84 |
{ |
| 85 |
OOTRACEERR1("Error:Failed to retrieve interface addresses\n"); |
| 86 |
return OO_FAILED; |
| 87 |
} |
| 88 |
} |
| 89 |
for(cur = gH323ep.ifList; cur; cur = cur->next) |
| 90 |
{ |
| 91 |
if(!strcmp(cur->name, "lo") || !strcmp(cur->addr, "127.0.0.1")) |
| 92 |
continue; |
| 93 |
break; |
| 94 |
} |
| 95 |
if(cur) |
| 96 |
{ |
| 97 |
strcpy(pGkClient->localRASIP, cur->addr); |
| 98 |
} |
| 99 |
else{ |
| 100 |
OOTRACEERR1("Error:Failed to assign a local RAS IP address\n"); |
| 101 |
return OO_FAILED; |
| 102 |
} |
| 103 |
} |
| 104 |
OOTRACEINFO2("Using local RAS Ip address %s\n", pGkClient->localRASIP); |
| 105 |
#endif |
| 106 |
if(OO_OK != ooGkClientSetGkMode(pGkClient, eGkMode, szGkAddr, iGkPort)) |
| 107 |
{ |
| 108 |
OOTRACEERR1("Error:Failed to set Gk mode\n"); |
| 109 |
memReset(&gH323ep.ctxt); |
| 110 |
return OO_FAILED; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
pGkClient->grqTimeout = DEFAULT_GRQ_TIMEOUT; |
| 115 |
pGkClient->rrqTimeout = DEFAULT_RRQ_TIMEOUT; |
| 116 |
pGkClient->regTimeout = DEFAULT_REG_TTL; |
| 117 |
pGkClient->arqTimeout = DEFAULT_ARQ_TIMEOUT; |
| 118 |
pGkClient->drqTimeout = DEFAULT_DRQ_TIMEOUT; |
| 119 |
dListInit(&pGkClient->callsPendingList); |
| 120 |
dListInit(&pGkClient->callsAdmittedList); |
| 121 |
dListInit(&pGkClient->timerList); |
| 122 |
pGkClient->state = GkClientIdle; |
| 123 |
return OO_OK; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
int ooGkClientSetCallbacks |
| 128 |
(ooGkClient *pGkClient, OOGKCLIENTCALLBACKS callbacks) |
| 129 |
{ |
| 130 |
pGkClient->callbacks.onReceivedRegistrationConfirm = |
| 131 |
callbacks.onReceivedRegistrationConfirm; |
| 132 |
pGkClient->callbacks.onReceivedUnregistrationConfirm = |
| 133 |
callbacks.onReceivedUnregistrationConfirm; |
| 134 |
pGkClient->callbacks.onReceivedUnregistrationRequest = |
| 135 |
callbacks.onReceivedUnregistrationRequest; |
| 136 |
return OO_OK; |
| 137 |
} |
| 138 |
|
| 139 |
int ooGkClientReInit(ooGkClient *pGkClient) |
| 140 |
{ |
| 141 |
|
| 142 |
ooGkClientCloseChannel(pGkClient); |
| 143 |
pGkClient->gkRasIP[0]='\0'; |
| 144 |
pGkClient->gkCallSignallingIP[0]='\0'; |
| 145 |
pGkClient->gkRasPort = 0; |
| 146 |
pGkClient->gkCallSignallingPort = 0; |
| 147 |
pGkClient->rrqRetries = 0; |
| 148 |
pGkClient->grqRetries = 0; |
| 149 |
pGkClient->requestSeqNum = 0; |
| 150 |
|
| 151 |
dListFreeAll(&pGkClient->ctxt, &pGkClient->callsPendingList); |
| 152 |
dListFreeAll(&pGkClient->ctxt, &pGkClient->callsAdmittedList); |
| 153 |
dListFreeAll(&pGkClient->ctxt, &pGkClient->timerList); |
| 154 |
pGkClient->state = GkClientIdle; |
| 155 |
return OO_OK; |
| 156 |
} |
| 157 |
|
| 158 |
void ooGkClientPrintConfig(ooGkClient *pGkClient) |
| 159 |
{ |
| 160 |
OOTRACEINFO1("Gatekeeper Client Configuration:\n"); |
| 161 |
if(pGkClient->gkMode == RasUseSpecificGatekeeper) |
| 162 |
{ |
| 163 |
OOTRACEINFO1("\tGatekeeper mode - UseSpecificGatekeeper\n"); |
| 164 |
OOTRACEINFO3("\tGatekeeper To Use - %s:%d\n", pGkClient->gkRasIP, |
| 165 |
pGkClient->gkRasPort); |
| 166 |
} |
| 167 |
else if(pGkClient->gkMode == RasDiscoverGatekeeper) { |
| 168 |
OOTRACEINFO1("\tGatekeeper mode - RasDiscoverGatekeeper\n"); |
| 169 |
} |
| 170 |
else { |
| 171 |
OOTRACEERR1("Invalid GatekeeperMode\n"); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
int ooGkClientDestroy(void) |
| 176 |
{ |
| 177 |
ooGkClient *pGkClient = gH323ep.gkClient; |
| 178 |
|
| 179 |
if(gH323ep.gkClient) |
| 180 |
{ |
| 181 |
ast_mutex_lock(&pGkClient->Lock); |
| 182 |
gH323ep.gkClient = NULL; |
| 183 |
if(pGkClient->state == GkClientRegistered) |
| 184 |
{ |
| 185 |
OOTRACEINFO1("Unregistering from Gatekeeper\n"); |
| 186 |
if(ooGkClientSendURQ(pGkClient, NULL)!=OO_OK) |
| 187 |
OOTRACEERR1("Error:Failed to send URQ to gatekeeper\n"); |
| 188 |
} |
| 189 |
OOTRACEINFO1("Destroying Gatekeeper Client\n"); |
| 190 |
ooGkClientCloseChannel(pGkClient); |
| 191 |
freeContext(&pGkClient->msgCtxt); |
| 192 |
freeContext(&pGkClient->ctxt); |
| 193 |
ast_mutex_unlock(&pGkClient->Lock); |
| 194 |
ast_mutex_destroy(&pGkClient->Lock); |
| 195 |
memFreePtr(&gH323ep.ctxt, pGkClient); |
| 196 |
} |
| 197 |
return OO_OK; |
| 198 |
} |
| 199 |
|
| 200 |
int ooGkClientStart(ooGkClient *pGkClient) |
| 201 |
{ |
| 202 |
int iRet=0; |
| 203 |
iRet = ooGkClientCreateChannel(pGkClient); |
| 204 |
|
| 205 |
if(iRet != OO_OK) |
| 206 |
{ |
| 207 |
OOTRACEERR1("Error: GkClient Channel Creation failed\n"); |
| 208 |
return OO_FAILED; |
| 209 |
} |
| 210 |
|
| 211 |
ast_mutex_lock(&pGkClient->Lock); |
| 212 |
pGkClient->discoveryComplete = FALSE; |
| 213 |
iRet = ooGkClientSendGRQ(pGkClient); |
| 214 |
if(iRet != OO_OK) |
| 215 |
{ |
| 216 |
OOTRACEERR1("Error:Failed to send GRQ message\n"); |
| 217 |
pGkClient->state = GkClientGkErr; |
| 218 |
ast_mutex_unlock(&pGkClient->Lock); |
| 219 |
return OO_FAILED; |
| 220 |
} |
| 221 |
ast_mutex_unlock(&pGkClient->Lock); |
| 222 |
return OO_OK; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
int ooGkClientSetGkMode(ooGkClient *pGkClient, enum RasGatekeeperMode eGkMode, |
| 227 |
char *szGkAddr, int iGkPort ) |
| 228 |
{ |
| 229 |
pGkClient->gkMode = eGkMode; |
| 230 |
if(eGkMode == RasUseSpecificGatekeeper) |
| 231 |
{ |
| 232 |
OOTRACEINFO1("Gatekeeper Mode - RasUseSpecificGatekeeper\n"); |
| 233 |
if(szGkAddr) |
| 234 |
{ |
| 235 |
if(strlen(szGkAddr)>MAX_IP_LEN) |
| 236 |
{ |
| 237 |
OOTRACEERR2("Error:Invalid IP address specified - %s\n", szGkAddr); |
| 238 |
return OO_FAILED; |
| 239 |
} |
| 240 |
strcpy(pGkClient->gkRasIP, szGkAddr); |
| 241 |
} |
| 242 |
if(iGkPort) |
| 243 |
pGkClient->gkRasPort = iGkPort; |
| 244 |
else |
| 245 |
pGkClient->gkRasPort = DEFAULT_GKPORT; |
| 246 |
|
| 247 |
OOTRACEINFO3("Gatekeeper IP:port set to - %s:%d\n", |
| 248 |
szGkAddr, pGkClient->gkRasPort); |
| 249 |
} |
| 250 |
else if(eGkMode == RasDiscoverGatekeeper) { |
| 251 |
OOTRACEINFO1("Gatekeeper Mode - RasDiscoverGatekeeper\n"); |
| 252 |
} |
| 253 |
else if(eGkMode == RasNoGatekeeper) { |
| 254 |
OOTRACEINFO1("Gatekeeper Mode - RasNoGatekeeper\n"); |
| 255 |
} |
| 256 |
|
| 257 |
return OO_OK; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
int ooGkClientCreateChannel(ooGkClient *pGkClient) |
| 267 |
{ |
| 268 |
int ret=0; |
| 269 |
OOIPADDR ipaddrs; |
| 270 |
|
| 271 |
if((ret=ooSocketCreateUDP(&pGkClient->rasSocket, 4))!=ASN_OK) |
| 272 |
{ |
| 273 |
OOTRACEERR1("Failed to create RAS socket\n"); |
| 274 |
pGkClient->state = GkClientFailed; |
| 275 |
return OO_FAILED; |
| 276 |
} |
| 277 |
if(pGkClient->localRASPort) |
| 278 |
{ |
| 279 |
inet_pton(AF_INET, pGkClient->localRASIP, &ipaddrs); |
| 280 |
if( (ret=ooSocketBind( pGkClient->rasSocket, ipaddrs, |
| 281 |
pGkClient->localRASPort))!=ASN_OK ) |
| 282 |
{ |
| 283 |
OOTRACEERR1("ERROR:Failed to create RAS channel\n"); |
| 284 |
pGkClient->state = GkClientFailed; |
| 285 |
return OO_FAILED; |
| 286 |
} |
| 287 |
} |
| 288 |
else { |
| 289 |
ret = ooBindPort (OOUDP, pGkClient->rasSocket, pGkClient->localRASIP); |
| 290 |
if(ret == OO_FAILED) |
| 291 |
{ |
| 292 |
OOTRACEERR1("ERROR: Failed to bind port to RAS socket\n"); |
| 293 |
pGkClient->state = GkClientFailed; |
| 294 |
return OO_FAILED; |
| 295 |
} |
| 296 |
pGkClient->localRASPort = ret; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
if(!strcmp(pGkClient->localRASIP, "0.0.0.0")) |
| 301 |
{ |
| 302 |
OOTRACEDBGA1("Determining ip address for RAS channel " |
| 303 |
"multihomed mode. \n"); |
| 304 |
ret = ooSocketGetIpAndPort(pGkClient->rasSocket, pGkClient->localRASIP, |
| 305 |
20, &pGkClient->localRASPort, NULL); |
| 306 |
if(ret != ASN_OK) |
| 307 |
{ |
| 308 |
OOTRACEERR1("Error:Failed to retrieve local ip and port from " |
| 309 |
"socket for RAS channel(multihomed).\n"); |
| 310 |
pGkClient->state = GkClientFailed; |
| 311 |
return OO_FAILED; |
| 312 |
} |
| 313 |
OOTRACEDBGA3("Using local ip %s and port %d for RAS channel" |
| 314 |
"(multihomedMode).\n", pGkClient->localRASIP, |
| 315 |
pGkClient->localRASPort); |
| 316 |
} |
| 317 |
|
| 318 |
OOTRACEINFO1("H323 RAS channel creation - successful\n"); |
| 319 |
return OO_OK; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
int ooGkClientCloseChannel(ooGkClient *pGkClient) |
| 324 |
{ |
| 325 |
int ret; |
| 326 |
if(pGkClient->rasSocket != 0) |
| 327 |
{ |
| 328 |
ret = ooSocketClose(pGkClient->rasSocket); |
| 329 |
if(ret != ASN_OK) |
| 330 |
{ |
| 331 |
OOTRACEERR1("Error: failed to close RAS channel\n"); |
| 332 |
pGkClient->rasSocket = 0; |
| 333 |
return OO_FAILED; |
| 334 |
} |
| 335 |
pGkClient->rasSocket = 0; |
| 336 |
} |
| 337 |
OOTRACEINFO1("Closed RAS channel\n"); |
| 338 |
return OO_OK; |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
void ooGkClientFillVendor |
| 347 |
(ooGkClient *pGkClient, H225VendorIdentifier *pVendor ) |
| 348 |
{ |
| 349 |
pVendor->vendor.t35CountryCode = gH323ep.t35CountryCode; |
| 350 |
pVendor->vendor.t35Extension = gH323ep.t35Extension; |
| 351 |
pVendor->vendor.manufacturerCode = gH323ep.manufacturerCode; |
| 352 |
pVendor->enterpriseNumber.numids=0; |
| 353 |
if(gH323ep.productID) |
| 354 |
{ |
| 355 |
pVendor->m.productIdPresent = TRUE; |
| 356 |
pVendor->productId.numocts = ASN1MIN(strlen(gH323ep.productID), |
| 357 |
sizeof(pVendor->productId.data)); |
| 358 |
memcpy(pVendor->productId.data, gH323ep.productID, |
| 359 |
pVendor->productId.numocts); |
| 360 |
} |
| 361 |
if(gH323ep.versionID) |
| 362 |
{ |
| 363 |
pVendor->m.versionIdPresent = 1; |
| 364 |
pVendor->versionId.numocts = ASN1MIN(strlen(gH323ep.versionID), |
| 365 |
sizeof(pVendor->versionId.data)); |
| 366 |
memcpy(pVendor->versionId.data, gH323ep.versionID, |
| 367 |
pVendor->versionId.numocts); |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
int ooGkClientReceive(ooGkClient *pGkClient) |
| 373 |
{ |
| 374 |
ASN1OCTET recvBuf[ASN_K_ENCBUFSIZ]; |
| 375 |
int recvLen; |
| 376 |
char remoteHost[32]; |
| 377 |
int iFromPort=0; |
| 378 |
OOCTXT *pctxt=NULL; |
| 379 |
H225RasMessage *pRasMsg=NULL; |
| 380 |
int iRet=OO_OK; |
| 381 |
|
| 382 |
ast_mutex_lock(&pGkClient->Lock); |
| 383 |
pctxt = &pGkClient->msgCtxt; |
| 384 |
|
| 385 |
recvLen = ooSocketRecvFrom(pGkClient->rasSocket, recvBuf, 2048, remoteHost, |
| 386 |
32, &iFromPort); |
| 387 |
if(recvLen <0) |
| 388 |
{ |
| 389 |
OOTRACEERR1("Error:Failed to receive RAS message\n"); |
| 390 |
ast_mutex_unlock(&pGkClient->Lock); |
| 391 |
return OO_FAILED; |
| 392 |
} |
| 393 |
OOTRACEDBGA1("GkClient Received RAS Message\n"); |
| 394 |
|
| 395 |
|
| 396 |
if(pGkClient->discoveryComplete) |
| 397 |
{ |
| 398 |
if((strncmp(pGkClient->gkRasIP, remoteHost,strlen(pGkClient->gkRasIP)))|| |
| 399 |
(pGkClient->gkRasPort!= iFromPort) ) |
| 400 |
{ |
| 401 |
OOTRACEWARN3("WARN:Ignoring message received from unknown gatekeeper " |
| 402 |
"%s:%d\n", remoteHost, iFromPort); |
| 403 |
ast_mutex_unlock(&pGkClient->Lock); |
| 404 |
return OO_OK; |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
if(ASN_OK != setPERBuffer (pctxt, recvBuf, recvLen, TRUE ) ) |
| 409 |
{ |
| 410 |
OOTRACEERR1("Error:Failed to set PER buffer for RAS message decoding\n"); |
| 411 |
memReset(pctxt); |
| 412 |
pGkClient->state = GkClientFailed; |
| 413 |
ast_mutex_unlock(&pGkClient->Lock); |
| 414 |
return OO_FAILED; |
| 415 |
} |
| 416 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 417 |
if(!pRasMsg) |
| 418 |
{ |
| 419 |
OOTRACEERR1("Error: Failed to allocate memory for RAS message\n"); |
| 420 |
memReset(pctxt); |
| 421 |
pGkClient->state = GkClientFailed; |
| 422 |
ast_mutex_unlock(&pGkClient->Lock); |
| 423 |
return OO_FAILED; |
| 424 |
} |
| 425 |
#ifndef _COMPACT |
| 426 |
initializePrintHandler(&printHandler, "Received RAS Message"); |
| 427 |
|
| 428 |
setEventHandler (pctxt, &printHandler); |
| 429 |
#endif |
| 430 |
if(ASN_OK == asn1PD_H225RasMessage(pctxt, pRasMsg)) |
| 431 |
{ |
| 432 |
#ifndef _COMPACT |
| 433 |
finishPrint(); |
| 434 |
removeEventHandler(pctxt); |
| 435 |
#endif |
| 436 |
iRet=ooGkClientHandleRASMessage( pGkClient, pRasMsg ); |
| 437 |
if(iRet != OO_OK) |
| 438 |
{ |
| 439 |
OOTRACEERR1("Error: Failed to handle received RAS message\n"); |
| 440 |
pGkClient->state = GkClientGkErr; |
| 441 |
} |
| 442 |
memReset(pctxt); |
| 443 |
} |
| 444 |
else{ |
| 445 |
OOTRACEERR1("ERROR:Failed to decode received RAS message- ignoring" |
| 446 |
"received message.\n"); |
| 447 |
#ifndef _COMPACT |
| 448 |
removeEventHandler(pctxt); |
| 449 |
#endif |
| 450 |
memReset(pctxt); |
| 451 |
ast_mutex_unlock(&pGkClient->Lock); |
| 452 |
return OO_FAILED; |
| 453 |
} |
| 454 |
ast_mutex_unlock(&pGkClient->Lock); |
| 455 |
return iRet; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
int ooGkClientHandleRASMessage(ooGkClient *pGkClient, H225RasMessage *pRasMsg) |
| 466 |
{ |
| 467 |
int iRet = OO_OK; |
| 468 |
switch( pRasMsg->t) |
| 469 |
{ |
| 470 |
case T_H225RasMessage_gatekeeperConfirm: |
| 471 |
OOTRACEINFO1("Gatekeeper Confirmed (GCF) message received.\n"); |
| 472 |
iRet = ooGkClientHandleGatekeeperConfirm(pGkClient, |
| 473 |
pRasMsg->u.gatekeeperConfirm); |
| 474 |
break; |
| 475 |
case T_H225RasMessage_gatekeeperReject: |
| 476 |
OOTRACEINFO1("Gatekeeper Reject (GRJ) message received\n"); |
| 477 |
iRet = ooGkClientHandleGatekeeperReject(pGkClient, |
| 478 |
pRasMsg->u.gatekeeperReject); |
| 479 |
break; |
| 480 |
case T_H225RasMessage_registrationConfirm: |
| 481 |
OOTRACEINFO1("Registration Confirm (RCF) message received\n"); |
| 482 |
iRet = ooGkClientHandleRegistrationConfirm(pGkClient, |
| 483 |
pRasMsg->u.registrationConfirm ); |
| 484 |
break; |
| 485 |
case T_H225RasMessage_registrationReject: |
| 486 |
OOTRACEINFO1("Registration Reject (RRJ) message received.\n"); |
| 487 |
iRet = ooGkClientHandleRegistrationReject(pGkClient, |
| 488 |
pRasMsg->u.registrationReject); |
| 489 |
break; |
| 490 |
case T_H225RasMessage_infoRequest: |
| 491 |
|
| 492 |
break; |
| 493 |
case T_H225RasMessage_admissionConfirm: |
| 494 |
OOTRACEINFO1("Admission Confirm (ACF) message received\n"); |
| 495 |
iRet = ooGkClientHandleAdmissionConfirm(pGkClient, |
| 496 |
pRasMsg->u.admissionConfirm); |
| 497 |
break; |
| 498 |
case T_H225RasMessage_unregistrationRequest: |
| 499 |
OOTRACEINFO1("UnRegistration Request (URQ) message received.\n"); |
| 500 |
iRet = ooGkClientHandleUnregistrationRequest(pGkClient, |
| 501 |
pRasMsg->u.unregistrationRequest); |
| 502 |
break; |
| 503 |
case T_H225RasMessage_unregistrationConfirm: |
| 504 |
OOTRACEINFO1("UnRegistration Confirm (UCF) message received.\n"); |
| 505 |
break; |
| 506 |
case T_H225RasMessage_unregistrationReject: |
| 507 |
OOTRACEINFO1("UnRegistration Reject (URJ) message received.\n"); |
| 508 |
break; |
| 509 |
case T_H225RasMessage_admissionReject: |
| 510 |
OOTRACEINFO1("Admission Reject (ARJ) message received.\n"); |
| 511 |
iRet = ooGkClientHandleAdmissionReject(pGkClient, |
| 512 |
pRasMsg->u.admissionReject); |
| 513 |
break; |
| 514 |
case T_H225RasMessage_disengageConfirm: |
| 515 |
iRet = ooGkClientHandleDisengageConfirm(pGkClient, |
| 516 |
pRasMsg->u.disengageConfirm); |
| 517 |
break; |
| 518 |
case T_H225RasMessage_disengageReject: |
| 519 |
case T_H225RasMessage_bandwidthConfirm: |
| 520 |
case T_H225RasMessage_bandwidthReject: |
| 521 |
case T_H225RasMessage_locationRequest: |
| 522 |
case T_H225RasMessage_locationConfirm: |
| 523 |
case T_H225RasMessage_locationReject: |
| 524 |
case T_H225RasMessage_infoRequestResponse: |
| 525 |
case T_H225RasMessage_nonStandardMessage: |
| 526 |
case T_H225RasMessage_unknownMessageResponse: |
| 527 |
case T_H225RasMessage_requestInProgress: |
| 528 |
case T_H225RasMessage_resourcesAvailableIndicate: |
| 529 |
case T_H225RasMessage_resourcesAvailableConfirm: |
| 530 |
case T_H225RasMessage_infoRequestAck: |
| 531 |
case T_H225RasMessage_infoRequestNak: |
| 532 |
case T_H225RasMessage_serviceControlIndication: |
| 533 |
case T_H225RasMessage_serviceControlResponse: |
| 534 |
case T_H225RasMessage_admissionConfirmSequence: |
| 535 |
default: |
| 536 |
|
| 537 |
iRet= OO_OK; |
| 538 |
} |
| 539 |
|
| 540 |
return iRet; |
| 541 |
} |
| 542 |
|
| 543 |
#ifndef _COMPACT |
| 544 |
void ooGkClientPrintMessage |
| 545 |
(ooGkClient *pGkClient, ASN1OCTET *msg, ASN1UINT len) |
| 546 |
{ |
| 547 |
OOCTXT ctxt; |
| 548 |
H225RasMessage rasMsg; |
| 549 |
int ret; |
| 550 |
|
| 551 |
initContext(&ctxt); |
| 552 |
setPERBuffer(&ctxt, msg, len, TRUE); |
| 553 |
initializePrintHandler(&printHandler, "Sending RAS Message"); |
| 554 |
setEventHandler(&ctxt, &printHandler); |
| 555 |
|
| 556 |
ret = asn1PD_H225RasMessage(&ctxt, &rasMsg); |
| 557 |
if(ret != ASN_OK) |
| 558 |
{ |
| 559 |
OOTRACEERR1("Error: Failed to decode RAS message\n"); |
| 560 |
} |
| 561 |
finishPrint(); |
| 562 |
freeContext(&ctxt); |
| 563 |
} |
| 564 |
#endif |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
int ooGkClientSendMsg(ooGkClient *pGkClient, H225RasMessage *pRasMsg) |
| 570 |
{ |
| 571 |
ASN1OCTET msgBuf[MAXMSGLEN]; |
| 572 |
ASN1OCTET *msgPtr=NULL; |
| 573 |
int iLen; |
| 574 |
|
| 575 |
OOCTXT *pctxt = &pGkClient->msgCtxt; |
| 576 |
|
| 577 |
setPERBuffer( pctxt, msgBuf, MAXMSGLEN, TRUE ); |
| 578 |
if ( ASN_OK == asn1PE_H225RasMessage(pctxt, pRasMsg) ) |
| 579 |
{ |
| 580 |
OOTRACEDBGC1("Ras message encoding - successful\n"); |
| 581 |
} |
| 582 |
else { |
| 583 |
OOTRACEERR1("Error: RAS message encoding failed\n"); |
| 584 |
return OO_FAILED; |
| 585 |
} |
| 586 |
|
| 587 |
msgPtr = encodeGetMsgPtr( pctxt, &iLen ); |
| 588 |
|
| 589 |
if(pGkClient->gkMode == RasUseSpecificGatekeeper || |
| 590 |
pGkClient->discoveryComplete) |
| 591 |
{ |
| 592 |
if(ASN_OK != ooSocketSendTo( pGkClient->rasSocket, msgPtr, iLen, |
| 593 |
pGkClient->gkRasIP, pGkClient->gkRasPort)) |
| 594 |
{ |
| 595 |
OOTRACEERR1("Error sending RAS message\n"); |
| 596 |
return OO_FAILED; |
| 597 |
} |
| 598 |
} |
| 599 |
else if(pGkClient->gkMode == RasDiscoverGatekeeper && |
| 600 |
!pGkClient->discoveryComplete) { |
| 601 |
if(ASN_OK != ooSocketSendTo(pGkClient->rasSocket, msgPtr, iLen, |
| 602 |
MULTICAST_GKADDRESS, MULTICAST_GKPORT)) |
| 603 |
{ |
| 604 |
OOTRACEERR1("Error sending multicast RAS message\n" ); |
| 605 |
return OO_FAILED; |
| 606 |
} |
| 607 |
} |
| 608 |
else { |
| 609 |
OOTRACEERR1("Error: GkClient in invalid state.\n"); |
| 610 |
return OO_FAILED; |
| 611 |
} |
| 612 |
#ifndef _COMPACT |
| 613 |
ooGkClientPrintMessage(pGkClient, msgPtr, iLen); |
| 614 |
#endif |
| 615 |
return OO_OK; |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
int ooGkClientSendGRQ(ooGkClient *pGkClient) |
| 621 |
{ |
| 622 |
int iRet; |
| 623 |
H225RasMessage *pRasMsg=NULL; |
| 624 |
H225GatekeeperRequest *pGkReq=NULL; |
| 625 |
H225TransportAddress_ipAddress *pRasAddress; |
| 626 |
OOCTXT *pctxt = &pGkClient->msgCtxt; |
| 627 |
ooGkClientTimerCb *cbData=NULL; |
| 628 |
|
| 629 |
ast_mutex_lock(&pGkClient->Lock); |
| 630 |
|
| 631 |
|
| 632 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 633 |
if(!pRasMsg) |
| 634 |
{ |
| 635 |
OOTRACEERR1("Error: Memory allocation for GRQ RAS message failed\n"); |
| 636 |
pGkClient->state = GkClientFailed; |
| 637 |
ast_mutex_unlock(&pGkClient->Lock); |
| 638 |
return OO_FAILED; |
| 639 |
} |
| 640 |
|
| 641 |
pGkReq = (H225GatekeeperRequest*)memAlloc(pctxt, |
| 642 |
sizeof(H225GatekeeperRequest)); |
| 643 |
if(!pGkReq) |
| 644 |
{ |
| 645 |
OOTRACEERR1("Error:Memory allocation for GRQ failed\n"); |
| 646 |
memReset(pctxt); |
| 647 |
pGkClient->state = GkClientFailed; |
| 648 |
ast_mutex_unlock(&pGkClient->Lock); |
| 649 |
return OO_FAILED; |
| 650 |
} |
| 651 |
memset(pGkReq, 0, sizeof(H225GatekeeperRequest)); |
| 652 |
pRasMsg->t = T_H225RasMessage_gatekeeperRequest; |
| 653 |
pRasMsg->u.gatekeeperRequest = pGkReq; |
| 654 |
|
| 655 |
|
| 656 |
pGkReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 657 |
if ( !pGkReq->requestSeqNum ) |
| 658 |
pGkReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 659 |
|
| 660 |
pGkReq->protocolIdentifier = gProtocolID; |
| 661 |
pGkReq->m.nonStandardDataPresent=0; |
| 662 |
pGkReq->rasAddress.t=T_H225TransportAddress_ipAddress; |
| 663 |
pRasAddress = (H225TransportAddress_ipAddress*)memAlloc(pctxt, |
| 664 |
sizeof(H225TransportAddress_ipAddress)); |
| 665 |
if(!pRasAddress) |
| 666 |
{ |
| 667 |
OOTRACEERR1("Error: Memory allocation for Ras Address of GRQ message " |
| 668 |
"failed\n"); |
| 669 |
memReset(&pGkClient->msgCtxt); |
| 670 |
pGkClient->state = GkClientFailed; |
| 671 |
ast_mutex_unlock(&pGkClient->Lock); |
| 672 |
return OO_FAILED; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
inet_pton(AF_INET, pGkClient->localRASIP, pRasAddress->ip.data); |
| 677 |
|
| 678 |
pRasAddress->ip.numocts = 4; |
| 679 |
pRasAddress->port = pGkClient->localRASPort; |
| 680 |
pGkReq->rasAddress.u.ipAddress = pRasAddress; |
| 681 |
|
| 682 |
|
| 683 |
if(gH323ep.isGateway) |
| 684 |
pGkReq->endpointType.m.gatewayPresent = TRUE; |
| 685 |
else |
| 686 |
pGkReq->endpointType.m.terminalPresent = TRUE; |
| 687 |
|
| 688 |
pGkReq->endpointType.m.nonStandardDataPresent=0; |
| 689 |
pGkReq->endpointType.m.vendorPresent=1; |
| 690 |
|
| 691 |
ooGkClientFillVendor(pGkClient, &pGkReq->endpointType.vendor); |
| 692 |
|
| 693 |
|
| 694 |
pGkReq->m.endpointAliasPresent=TRUE; |
| 695 |
if(OO_OK != ooPopulateAliasList(&pGkClient->msgCtxt, gH323ep.aliases, |
| 696 |
&pGkReq->endpointAlias, 0)) |
| 697 |
{ |
| 698 |
OOTRACEERR1("Error Failed to fill alias information for GRQ message\n"); |
| 699 |
memReset(&pGkClient->msgCtxt); |
| 700 |
pGkClient->state = GkClientFailed; |
| 701 |
ast_mutex_unlock(&pGkClient->Lock); |
| 702 |
return OO_FAILED; |
| 703 |
} |
| 704 |
iRet = ooGkClientSendMsg(pGkClient, pRasMsg); |
| 705 |
if(iRet != OO_OK) |
| 706 |
{ |
| 707 |
OOTRACEERR1("Error: Failed to send GRQ message\n"); |
| 708 |
memReset(&pGkClient->msgCtxt); |
| 709 |
pGkClient->state = GkClientGkErr; |
| 710 |
ast_mutex_unlock(&pGkClient->Lock); |
| 711 |
return OO_FAILED; |
| 712 |
} |
| 713 |
OOTRACEINFO1("Sent GRQ message\n"); |
| 714 |
cbData = (ooGkClientTimerCb*) memAlloc |
| 715 |
(&pGkClient->ctxt, sizeof(ooGkClientTimerCb)); |
| 716 |
if(!cbData) |
| 717 |
{ |
| 718 |
OOTRACEERR1("Error:Failed to allocate memory to GRQ timer callback\n"); |
| 719 |
pGkClient->state = GkClientFailed; |
| 720 |
ast_mutex_unlock(&pGkClient->Lock); |
| 721 |
return OO_FAILED; |
| 722 |
} |
| 723 |
cbData->timerType = OO_GRQ_TIMER; |
| 724 |
cbData->pGkClient = pGkClient; |
| 725 |
if(!ooTimerCreate(&pGkClient->ctxt, &pGkClient->timerList, |
| 726 |
&ooGkClientGRQTimerExpired, pGkClient->grqTimeout, |
| 727 |
cbData, FALSE)) |
| 728 |
{ |
| 729 |
OOTRACEERR1("Error:Unable to create GRQ timer.\n "); |
| 730 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 731 |
pGkClient->state = GkClientFailed; |
| 732 |
ast_mutex_unlock(&pGkClient->Lock); |
| 733 |
return OO_FAILED; |
| 734 |
} |
| 735 |
ast_mutex_unlock(&pGkClient->Lock); |
| 736 |
return OO_OK; |
| 737 |
} |
| 738 |
|
| 739 |
int ooGkClientHandleGatekeeperReject |
| 740 |
(ooGkClient *pGkClient, H225GatekeeperReject *pGatekeeperReject) |
| 741 |
{ |
| 742 |
unsigned int x=0; |
| 743 |
DListNode *pNode = NULL; |
| 744 |
OOTimer *pTimer = NULL; |
| 745 |
|
| 746 |
if(pGkClient->gkMode == RasUseSpecificGatekeeper) |
| 747 |
{ |
| 748 |
|
| 749 |
for(x=0; x<pGkClient->timerList.count; x++) |
| 750 |
{ |
| 751 |
pNode = dListFindByIndex(&pGkClient->timerList, x); |
| 752 |
pTimer = (OOTimer*)pNode->data; |
| 753 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_GRQ_TIMER) |
| 754 |
{ |
| 755 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 756 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer); |
| 757 |
OOTRACEDBGA1("Deleted GRQ Timer.\n"); |
| 758 |
break; |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
pGkClient->state = GkClientGkErr; |
| 763 |
switch(pGatekeeperReject->rejectReason.t) |
| 764 |
{ |
| 765 |
case T_H225GatekeeperRejectReason_resourceUnavailable: |
| 766 |
OOTRACEERR1("Error: Gatekeeper Reject - Resource Unavailable\n"); |
| 767 |
break; |
| 768 |
case T_H225GatekeeperRejectReason_terminalExcluded: |
| 769 |
OOTRACEERR1("Error: Gatekeeper Reject - Terminal Excluded\n"); |
| 770 |
break; |
| 771 |
case T_H225GatekeeperRejectReason_invalidRevision: |
| 772 |
OOTRACEERR1("Error: Gatekeeper Reject - Invalid Revision\n"); |
| 773 |
break; |
| 774 |
case T_H225GatekeeperRejectReason_undefinedReason: |
| 775 |
OOTRACEERR1("Error: Gatekeeper Reject - Undefined Reason\n"); |
| 776 |
break; |
| 777 |
case T_H225GatekeeperRejectReason_securityDenial: |
| 778 |
OOTRACEERR1("Error: Gatekeeper Reject - Security Denial\n"); |
| 779 |
break; |
| 780 |
case T_H225GatekeeperRejectReason_genericDataReason: |
| 781 |
OOTRACEERR1("Error: Gatekeeper Reject - Generic Data Reason\n"); |
| 782 |
break; |
| 783 |
case T_H225GatekeeperRejectReason_neededFeatureNotSupported: |
| 784 |
OOTRACEERR1("Error: Gatekeeper Reject - Needed Feature Not " |
| 785 |
"Supported\n"); |
| 786 |
break; |
| 787 |
case T_H225GatekeeperRejectReason_securityError: |
| 788 |
OOTRACEERR1("Error:Gatekeeper Reject - Security Error\n"); |
| 789 |
break; |
| 790 |
default: |
| 791 |
OOTRACEERR1("Error: Gatekeeper Reject - Invalid reason\n"); |
| 792 |
} |
| 793 |
return OO_OK; |
| 794 |
} |
| 795 |
OOTRACEDBGB1("Gatekeeper Reject response received for multicast GRQ " |
| 796 |
"request\n"); |
| 797 |
return OO_OK; |
| 798 |
|
| 799 |
} |
| 800 |
|
| 801 |
int ooGkClientHandleGatekeeperConfirm |
| 802 |
(ooGkClient *pGkClient, H225GatekeeperConfirm *pGatekeeperConfirm) |
| 803 |
{ |
| 804 |
int iRet=0; |
| 805 |
unsigned int x=0; |
| 806 |
DListNode *pNode = NULL; |
| 807 |
OOTimer *pTimer = NULL; |
| 808 |
H225TransportAddress_ipAddress *pRasAddress; |
| 809 |
|
| 810 |
if(pGkClient->discoveryComplete) |
| 811 |
{ |
| 812 |
OOTRACEDBGB1("Ignoring GKConfirm as Gatekeeper has been discovered\n"); |
| 813 |
return OO_OK; |
| 814 |
} |
| 815 |
|
| 816 |
if(pGatekeeperConfirm->m.gatekeeperIdentifierPresent) |
| 817 |
{ |
| 818 |
pGkClient->gkId.nchars = pGatekeeperConfirm->gatekeeperIdentifier.nchars; |
| 819 |
if (pGkClient->gkId.data) { |
| 820 |
memFreePtr(&pGkClient->ctxt, pGkClient->gkId.data); |
| 821 |
} |
| 822 |
pGkClient->gkId.data = (ASN116BITCHAR*)memAlloc(&pGkClient->ctxt, |
| 823 |
sizeof(ASN116BITCHAR)*pGkClient->gkId.nchars); |
| 824 |
if(!pGkClient->gkId.data) |
| 825 |
{ |
| 826 |
OOTRACEERR1("Error:Failed to allocate memory for GK ID data\n"); |
| 827 |
pGkClient->state = GkClientFailed; |
| 828 |
return OO_FAILED; |
| 829 |
} |
| 830 |
|
| 831 |
memcpy(pGkClient->gkId.data, |
| 832 |
pGatekeeperConfirm->gatekeeperIdentifier.data, |
| 833 |
sizeof(ASN116BITCHAR)* pGkClient->gkId.nchars); |
| 834 |
} |
| 835 |
else{ |
| 836 |
OOTRACEINFO1("ERROR:No Gatekeeper ID present in received GKConfirmed " |
| 837 |
"message\n"); |
| 838 |
pGkClient->gkId.nchars = 0; |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
if(pGatekeeperConfirm->rasAddress.t != T_H225TransportAddress_ipAddress) |
| 843 |
{ |
| 844 |
OOTRACEERR1("ERROR:Unsupported RAS address type in received Gk Confirm" |
| 845 |
" message.\n"); |
| 846 |
pGkClient->state = GkClientGkErr; |
| 847 |
return OO_FAILED; |
| 848 |
} |
| 849 |
pRasAddress = pGatekeeperConfirm->rasAddress.u.ipAddress; |
| 850 |
sprintf(pGkClient->gkRasIP, "%d.%d.%d.%d", pRasAddress->ip.data[0], |
| 851 |
pRasAddress->ip.data[1], |
| 852 |
pRasAddress->ip.data[2], |
| 853 |
pRasAddress->ip.data[3]); |
| 854 |
pGkClient->gkRasPort = pRasAddress->port; |
| 855 |
|
| 856 |
pGkClient->discoveryComplete = TRUE; |
| 857 |
pGkClient->state = GkClientDiscovered; |
| 858 |
OOTRACEINFO1("Gatekeeper Confirmed\n"); |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
for(x=0; x<pGkClient->timerList.count; x++) |
| 863 |
{ |
| 864 |
pNode = dListFindByIndex(&pGkClient->timerList, x); |
| 865 |
pTimer = (OOTimer*)pNode->data; |
| 866 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_GRQ_TIMER) |
| 867 |
{ |
| 868 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 869 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer); |
| 870 |
OOTRACEDBGA1("Deleted GRQ Timer.\n"); |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
iRet = ooGkClientSendRRQ(pGkClient, FALSE); |
| 875 |
if(iRet != OO_OK) |
| 876 |
{ |
| 877 |
OOTRACEERR1("Error:Failed to send initial RRQ\n"); |
| 878 |
return OO_FAILED; |
| 879 |
} |
| 880 |
return OO_OK; |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
int ooGkClientSendRRQ(ooGkClient *pGkClient, ASN1BOOL keepAlive) |
| 888 |
{ |
| 889 |
int iRet; |
| 890 |
H225RasMessage *pRasMsg=NULL; |
| 891 |
H225RegistrationRequest *pRegReq=NULL; |
| 892 |
OOCTXT *pctxt=NULL; |
| 893 |
H225TransportAddress *pTransportAddress=NULL; |
| 894 |
H225TransportAddress_ipAddress *pIpAddress=NULL; |
| 895 |
ooGkClientTimerCb *cbData =NULL; |
| 896 |
H225SupportedProtocols *pProtocol = NULL; |
| 897 |
H225VoiceCaps *pVoiceCaps = NULL; |
| 898 |
|
| 899 |
ast_mutex_lock(&pGkClient->Lock); |
| 900 |
|
| 901 |
pctxt = &pGkClient->msgCtxt; |
| 902 |
|
| 903 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 904 |
if(!pRasMsg) |
| 905 |
{ |
| 906 |
OOTRACEERR1("Error: Memory allocation for RRQ RAS message failed\n"); |
| 907 |
pGkClient->state = GkClientFailed; |
| 908 |
ast_mutex_unlock(&pGkClient->Lock); |
| 909 |
return OO_FAILED; |
| 910 |
} |
| 911 |
|
| 912 |
pRegReq = (H225RegistrationRequest*)memAlloc(pctxt, |
| 913 |
sizeof(H225RegistrationRequest)); |
| 914 |
if(!pRegReq) |
| 915 |
{ |
| 916 |
OOTRACEERR1("Error:Memory allocation for RRQ failed\n"); |
| 917 |
memReset(pctxt); |
| 918 |
pGkClient->state = GkClientFailed; |
| 919 |
ast_mutex_unlock(&pGkClient->Lock); |
| 920 |
return OO_FAILED; |
| 921 |
} |
| 922 |
memset(pRegReq, 0, sizeof(H225RegistrationRequest)); |
| 923 |
pRasMsg->t = T_H225RasMessage_registrationRequest; |
| 924 |
pRasMsg->u.registrationRequest = pRegReq; |
| 925 |
|
| 926 |
pRegReq->protocolIdentifier = gProtocolID; |
| 927 |
pRegReq->m.nonStandardDataPresent=0; |
| 928 |
|
| 929 |
pTransportAddress = (H225TransportAddress*) memAlloc(pctxt, |
| 930 |
sizeof(H225TransportAddress)); |
| 931 |
pIpAddress = (H225TransportAddress_ipAddress*) memAlloc(pctxt, |
| 932 |
sizeof(H225TransportAddress_ipAddress)); |
| 933 |
if(!pTransportAddress || !pIpAddress) |
| 934 |
{ |
| 935 |
OOTRACEERR1("Error:Failed to allocate memory for signalling address of " |
| 936 |
"RRQ message\n"); |
| 937 |
memReset(pctxt); |
| 938 |
pGkClient->state = GkClientFailed; |
| 939 |
ast_mutex_unlock(&pGkClient->Lock); |
| 940 |
return OO_FAILED; |
| 941 |
} |
| 942 |
pTransportAddress->t = T_H225TransportAddress_ipAddress; |
| 943 |
pTransportAddress->u.ipAddress = pIpAddress; |
| 944 |
inet_pton(AF_INET, pGkClient->localRASIP, pIpAddress->ip.data); |
| 945 |
pIpAddress->ip.numocts = 4; |
| 946 |
pIpAddress->port = gH323ep.listenPort; |
| 947 |
|
| 948 |
dListInit(&pRegReq->callSignalAddress); |
| 949 |
dListAppend(pctxt, &pRegReq->callSignalAddress, |
| 950 |
(void*)pTransportAddress); |
| 951 |
|
| 952 |
|
| 953 |
pTransportAddress = NULL; |
| 954 |
pIpAddress = NULL; |
| 955 |
pTransportAddress = (H225TransportAddress*) memAlloc(pctxt, |
| 956 |
sizeof(H225TransportAddress)); |
| 957 |
pIpAddress = (H225TransportAddress_ipAddress*) memAlloc(pctxt, |
| 958 |
sizeof(H225TransportAddress_ipAddress)); |
| 959 |
if(!pTransportAddress || !pIpAddress) |
| 960 |
{ |
| 961 |
OOTRACEERR1("Error:Failed to allocate memory for RAS address of " |
| 962 |
"RRQ message\n"); |
| 963 |
memReset(pctxt); |
| 964 |
pGkClient->state = GkClientFailed; |
| 965 |
ast_mutex_unlock(&pGkClient->Lock); |
| 966 |
return OO_FAILED; |
| 967 |
} |
| 968 |
|
| 969 |
pTransportAddress->t = T_H225TransportAddress_ipAddress; |
| 970 |
pTransportAddress->u.ipAddress = pIpAddress; |
| 971 |
|
| 972 |
inet_pton(AF_INET, pGkClient->localRASIP, pIpAddress->ip.data); |
| 973 |
|
| 974 |
pIpAddress->ip.numocts = 4; |
| 975 |
pIpAddress->port = pGkClient->localRASPort; |
| 976 |
|
| 977 |
dListInit(&pRegReq->rasAddress); |
| 978 |
dListAppend(pctxt, &pRegReq->rasAddress, |
| 979 |
(void*)pTransportAddress); |
| 980 |
|
| 981 |
|
| 982 |
if(gH323ep.isGateway) |
| 983 |
pRegReq->terminalType.m.gatewayPresent = TRUE; |
| 984 |
else |
| 985 |
pRegReq->terminalType.m.terminalPresent = TRUE; |
| 986 |
|
| 987 |
pRegReq->terminalType.m.vendorPresent=TRUE; |
| 988 |
ooGkClientFillVendor(pGkClient, &pRegReq->terminalType.vendor ); |
| 989 |
|
| 990 |
if (gH323ep.isGateway) { |
| 991 |
pRegReq->terminalType.gateway.m.protocolPresent = TRUE; |
| 992 |
pProtocol = (H225SupportedProtocols*) memAlloc(pctxt, |
| 993 |
sizeof(H225SupportedProtocols)); |
| 994 |
pVoiceCaps = (H225VoiceCaps*) memAlloc(pctxt, sizeof(H225VoiceCaps)); |
| 995 |
if(!pProtocol || !pVoiceCaps) { |
| 996 |
OOTRACEERR1("Error:Failed to allocate memory for protocol info of " |
| 997 |
"RRQ message\n"); |
| 998 |
memReset(pctxt); |
| 999 |
pGkClient->state = GkClientFailed; |
| 1000 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1001 |
return OO_FAILED; |
| 1002 |
} |
| 1003 |
|
| 1004 |
memset(pVoiceCaps, 0, sizeof(H225VoiceCaps)); |
| 1005 |
memset(pProtocol, 0, sizeof(H225SupportedProtocols)); |
| 1006 |
|
| 1007 |
pVoiceCaps->m.supportedPrefixesPresent = TRUE; |
| 1008 |
ooPopulatePrefixList(pctxt, gH323ep.aliases, &pVoiceCaps->supportedPrefixes); |
| 1009 |
|
| 1010 |
pProtocol->t = T_H225SupportedProtocols_voice; |
| 1011 |
pProtocol->u.voice = pVoiceCaps; |
| 1012 |
|
| 1013 |
dListInit(&pRegReq->terminalType.gateway.protocol); |
| 1014 |
dListAppend(pctxt, &pRegReq->terminalType.gateway.protocol, |
| 1015 |
(void*)pProtocol); |
| 1016 |
|
| 1017 |
} |
| 1018 |
|
| 1019 |
pRegReq->m.terminalAliasPresent=TRUE; |
| 1020 |
if(OO_OK != ooPopulateAliasList(pctxt, gH323ep.aliases, |
| 1021 |
&pRegReq->terminalAlias, 0)) { |
| 1022 |
OOTRACEERR1("Error filling alias for RRQ\n"); |
| 1023 |
memReset(pctxt); |
| 1024 |
pGkClient->state = GkClientFailed; |
| 1025 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1026 |
return OO_FAILED; |
| 1027 |
} |
| 1028 |
|
| 1029 |
if (pGkClient->gkId.nchars) { |
| 1030 |
pRegReq->m.gatekeeperIdentifierPresent=TRUE; |
| 1031 |
pRegReq->gatekeeperIdentifier.nchars = pGkClient->gkId.nchars; |
| 1032 |
pRegReq->gatekeeperIdentifier.data = (ASN116BITCHAR*)memAlloc |
| 1033 |
(pctxt, pGkClient->gkId.nchars*sizeof(ASN116BITCHAR)); |
| 1034 |
if(!pRegReq->gatekeeperIdentifier.data) |
| 1035 |
{ |
| 1036 |
OOTRACEERR1("Error: Failed to allocate memory for GKIdentifier in RRQ " |
| 1037 |
"message.\n"); |
| 1038 |
memReset(pctxt); |
| 1039 |
pGkClient->state = GkClientFailed; |
| 1040 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1041 |
return OO_FAILED; |
| 1042 |
} |
| 1043 |
memcpy(pRegReq->gatekeeperIdentifier.data, pGkClient->gkId.data, |
| 1044 |
pGkClient->gkId.nchars*sizeof(ASN116BITCHAR)); |
| 1045 |
} |
| 1046 |
|
| 1047 |
ooGkClientFillVendor(pGkClient, &pRegReq->endpointVendor); |
| 1048 |
|
| 1049 |
pRegReq->m.willSupplyUUIEsPresent=TRUE; |
| 1050 |
pRegReq->willSupplyUUIEs=FALSE; |
| 1051 |
|
| 1052 |
pRegReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 1053 |
if(!pRegReq->requestSeqNum) |
| 1054 |
pRegReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 1055 |
|
| 1056 |
pRegReq->discoveryComplete= pGkClient->discoveryComplete; |
| 1057 |
pRegReq->m.keepAlivePresent=TRUE; |
| 1058 |
pRegReq->keepAlive= keepAlive; |
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
if(keepAlive) { |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
pRegReq->endpointIdentifier.data = |
| 1075 |
(ASN116BITCHAR*)memAlloc(pctxt, pGkClient->endpointId.nchars*sizeof(ASN116BITCHAR)); |
| 1076 |
if (pRegReq->endpointIdentifier.data) { |
| 1077 |
pRegReq->endpointIdentifier.nchars = pGkClient->endpointId.nchars; |
| 1078 |
pRegReq->m.endpointIdentifierPresent = TRUE; |
| 1079 |
memcpy(pRegReq->endpointIdentifier.data, pGkClient->endpointId.data, pGkClient->endpointId.nchars*sizeof(ASN116BITCHAR)); |
| 1080 |
OOTRACEINFO1("Sending RRQ for re-registration (with EndpointID)\n"); |
| 1081 |
} |
| 1082 |
else { |
| 1083 |
OOTRACEERR1("Error: Failed to allocate memory for EndpointIdentifier in RRQ \n"); |
| 1084 |
memReset(pctxt); |
| 1085 |
pGkClient->state = GkClientFailed; |
| 1086 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1087 |
return OO_FAILED; |
| 1088 |
} |
| 1089 |
} |
| 1090 |
|
| 1091 |
pRegReq->m.timeToLivePresent = TRUE; |
| 1092 |
pRegReq->timeToLive = pGkClient->regTimeout; |
| 1093 |
|
| 1094 |
iRet = ooGkClientSendMsg(pGkClient, pRasMsg); |
| 1095 |
if(iRet != OO_OK) |
| 1096 |
{ |
| 1097 |
OOTRACEERR1("Error: Failed to send RRQ message\n"); |
| 1098 |
memReset(pctxt); |
| 1099 |
pGkClient->state = GkClientFailed; |
| 1100 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1101 |
return OO_FAILED; |
| 1102 |
} |
| 1103 |
OOTRACEINFO1("Sent RRQ message \n"); |
| 1104 |
|
| 1105 |
cbData = (ooGkClientTimerCb*) memAlloc |
| 1106 |
(&pGkClient->ctxt, sizeof(ooGkClientTimerCb)); |
| 1107 |
if(!cbData) |
| 1108 |
{ |
| 1109 |
OOTRACEERR1("Error:Failed to allocate memory to RRQ timer callback\n"); |
| 1110 |
pGkClient->state = GkClientFailed; |
| 1111 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1112 |
return OO_FAILED; |
| 1113 |
} |
| 1114 |
cbData->timerType = OO_RRQ_TIMER; |
| 1115 |
cbData->pGkClient = pGkClient; |
| 1116 |
if(!ooTimerCreate(&pGkClient->ctxt, &pGkClient->timerList, |
| 1117 |
&ooGkClientRRQTimerExpired, pGkClient->rrqTimeout, |
| 1118 |
cbData, FALSE)) |
| 1119 |
{ |
| 1120 |
OOTRACEERR1("Error:Unable to create GRQ timer.\n "); |
| 1121 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 1122 |
pGkClient->state = GkClientFailed; |
| 1123 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1124 |
return OO_FAILED; |
| 1125 |
} |
| 1126 |
|
| 1127 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1128 |
return OO_OK; |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
int ooGkClientHandleRegistrationConfirm |
| 1138 |
(ooGkClient *pGkClient, H225RegistrationConfirm *pRegistrationConfirm) |
| 1139 |
{ |
| 1140 |
int i=0; |
| 1141 |
unsigned int x=0; |
| 1142 |
OOTimer *pTimer = NULL; |
| 1143 |
DListNode *pNode = NULL; |
| 1144 |
H225TransportAddress *pCallSigAddr=NULL; |
| 1145 |
ooGkClientTimerCb *cbData; |
| 1146 |
ASN1UINT regTTL=0; |
| 1147 |
|
| 1148 |
if (pGkClient->endpointId.data) |
| 1149 |
memFreePtr(&pGkClient->ctxt, pGkClient->endpointId.data); |
| 1150 |
pGkClient->endpointId.nchars = |
| 1151 |
pRegistrationConfirm->endpointIdentifier.nchars; |
| 1152 |
pGkClient->endpointId.data = (ASN116BITCHAR*)memAlloc(&pGkClient->ctxt, |
| 1153 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 1154 |
if(!pGkClient->endpointId.data) |
| 1155 |
{ |
| 1156 |
OOTRACEERR1("Error:Failed to allocate memory for endpoint Id.\n"); |
| 1157 |
pGkClient->state = GkClientFailed; |
| 1158 |
return OO_FAILED; |
| 1159 |
} |
| 1160 |
|
| 1161 |
memcpy(pGkClient->endpointId.data, |
| 1162 |
pRegistrationConfirm->endpointIdentifier.data, |
| 1163 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
if(pRegistrationConfirm->m.gatekeeperIdentifierPresent && pGkClient->gkId.nchars == 0) |
| 1168 |
{ |
| 1169 |
pGkClient->gkId.nchars = pRegistrationConfirm->gatekeeperIdentifier.nchars; |
| 1170 |
pGkClient->gkId.data = (ASN116BITCHAR*)memAlloc(&pGkClient->ctxt, |
| 1171 |
sizeof(ASN116BITCHAR)*pGkClient->gkId.nchars); |
| 1172 |
if(!pGkClient->gkId.data) |
| 1173 |
{ |
| 1174 |
OOTRACEERR1("Error:Failed to allocate memory for GK ID data\n"); |
| 1175 |
pGkClient->state = GkClientFailed; |
| 1176 |
return OO_FAILED; |
| 1177 |
} |
| 1178 |
|
| 1179 |
memcpy(pGkClient->gkId.data, |
| 1180 |
pRegistrationConfirm->gatekeeperIdentifier.data, |
| 1181 |
sizeof(ASN116BITCHAR)* pGkClient->gkId.nchars); |
| 1182 |
} |
| 1183 |
|
| 1184 |
|
| 1185 |
for(i=0; i<(int)pRegistrationConfirm->callSignalAddress.count; i++) |
| 1186 |
{ |
| 1187 |
pNode = dListFindByIndex(&pRegistrationConfirm->callSignalAddress, i); |
| 1188 |
if(!pNode) |
| 1189 |
{ |
| 1190 |
OOTRACEERR1("Error:Invalid Registration confirmed message\n"); |
| 1191 |
OOTRACEINFO1("Ignoring RCF, will retransmit RRQ after timeout\n"); |
| 1192 |
return OO_FAILED; |
| 1193 |
} |
| 1194 |
pCallSigAddr = (H225TransportAddress*)pNode->data; |
| 1195 |
if(pCallSigAddr->t != T_H225TransportAddress_ipAddress) |
| 1196 |
continue; |
| 1197 |
sprintf(pGkClient->gkCallSignallingIP, "%d.%d.%d.%d", |
| 1198 |
pCallSigAddr->u.ipAddress->ip.data[0], |
| 1199 |
pCallSigAddr->u.ipAddress->ip.data[1], |
| 1200 |
pCallSigAddr->u.ipAddress->ip.data[2], |
| 1201 |
pCallSigAddr->u.ipAddress->ip.data[3]); |
| 1202 |
pGkClient->gkCallSignallingPort = pCallSigAddr->u.ipAddress->port; |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
if(pRegistrationConfirm->m.terminalAliasPresent) |
| 1207 |
{ |
| 1208 |
ooGkClientUpdateRegisteredAliases(pGkClient, |
| 1209 |
&pRegistrationConfirm->terminalAlias, TRUE); |
| 1210 |
} |
| 1211 |
else{ |
| 1212 |
ooGkClientUpdateRegisteredAliases(pGkClient, NULL, TRUE); |
| 1213 |
} |
| 1214 |
|
| 1215 |
|
| 1216 |
if(pRegistrationConfirm->m.timeToLivePresent) |
| 1217 |
{ |
| 1218 |
pGkClient->regTimeout = pRegistrationConfirm->timeToLive; |
| 1219 |
OOTRACEINFO2("Gatekeeper supports KeepAlive, Registration TTL is %d\n", |
| 1220 |
pRegistrationConfirm->timeToLive); |
| 1221 |
|
| 1222 |
if(pGkClient->regTimeout > DEFAULT_TTL_OFFSET) |
| 1223 |
regTTL = pGkClient->regTimeout - DEFAULT_TTL_OFFSET; |
| 1224 |
else { |
| 1225 |
regTTL = pGkClient->regTimeout - 1; |
| 1226 |
if (regTTL <= 0) |
| 1227 |
regTTL = 1; |
| 1228 |
} |
| 1229 |
|
| 1230 |
cbData = (ooGkClientTimerCb*) memAlloc |
| 1231 |
(&pGkClient->ctxt, sizeof(ooGkClientTimerCb)); |
| 1232 |
if(!cbData) |
| 1233 |
{ |
| 1234 |
OOTRACEERR1("Error:Failed to allocate memory for Registration timer." |
| 1235 |
"\n"); |
| 1236 |
pGkClient->state = GkClientFailed; |
| 1237 |
return OO_FAILED; |
| 1238 |
} |
| 1239 |
cbData->timerType = OO_REG_TIMER; |
| 1240 |
cbData->pGkClient = pGkClient; |
| 1241 |
if(!ooTimerCreate(&pGkClient->ctxt, &pGkClient->timerList, |
| 1242 |
&ooGkClientREGTimerExpired, regTTL, |
| 1243 |
cbData, FALSE)) |
| 1244 |
{ |
| 1245 |
OOTRACEERR1("Error:Unable to create REG timer.\n "); |
| 1246 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 1247 |
pGkClient->state = GkClientFailed; |
| 1248 |
return OO_FAILED; |
| 1249 |
} |
| 1250 |
|
| 1251 |
} |
| 1252 |
else{ |
| 1253 |
pGkClient->regTimeout = 0; |
| 1254 |
OOTRACEINFO1("Gatekeeper does not support KeepAlive.\n"); |
| 1255 |
} |
| 1256 |
|
| 1257 |
if(pRegistrationConfirm->m.preGrantedARQPresent) |
| 1258 |
{ |
| 1259 |
memcpy(&pGkClient->gkInfo.preGrantedARQ, |
| 1260 |
&pRegistrationConfirm->preGrantedARQ, |
| 1261 |
sizeof(H225RegistrationConfirm_preGrantedARQ)); |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
pNode = NULL; |
| 1267 |
for(x=0; x<pGkClient->timerList.count; x++) |
| 1268 |
{ |
| 1269 |
pNode = dListFindByIndex(&pGkClient->timerList, x); |
| 1270 |
pTimer = (OOTimer*)pNode->data; |
| 1271 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_RRQ_TIMER) |
| 1272 |
{ |
| 1273 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 1274 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer); |
| 1275 |
OOTRACEDBGA1("Deleted RRQ Timer.\n"); |
| 1276 |
} |
| 1277 |
} |
| 1278 |
pGkClient->state = GkClientRegistered; |
| 1279 |
pGkClient->rrqRetries = 0; |
| 1280 |
if(pGkClient->callbacks.onReceivedRegistrationConfirm) |
| 1281 |
pGkClient->callbacks.onReceivedRegistrationConfirm(pRegistrationConfirm, |
| 1282 |
gH323ep.aliases); |
| 1283 |
return OO_OK; |
| 1284 |
} |
| 1285 |
|
| 1286 |
int ooGkClientHandleRegistrationReject |
| 1287 |
(ooGkClient *pGkClient, H225RegistrationReject *pRegistrationReject) |
| 1288 |
{ |
| 1289 |
int iRet=0; |
| 1290 |
unsigned int x=0; |
| 1291 |
DListNode *pNode = NULL; |
| 1292 |
OOTimer *pTimer = NULL; |
| 1293 |
ooGkClientTimerCb *cbData=NULL; |
| 1294 |
|
| 1295 |
|
| 1296 |
for(x=0; x<pGkClient->timerList.count; x++) |
| 1297 |
{ |
| 1298 |
pNode = dListFindByIndex(&pGkClient->timerList, x); |
| 1299 |
pTimer = (OOTimer*)pNode->data; |
| 1300 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_RRQ_TIMER) |
| 1301 |
{ |
| 1302 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 1303 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer); |
| 1304 |
OOTRACEDBGA1("Deleted RRQ Timer.\n"); |
| 1305 |
} |
| 1306 |
} |
| 1307 |
|
| 1308 |
switch(pRegistrationReject->rejectReason.t) |
| 1309 |
{ |
| 1310 |
case T_H225RegistrationRejectReason_discoveryRequired: |
| 1311 |
OOTRACEINFO1("RRQ Rejected - Discovery Required\n"); |
| 1312 |
|
| 1313 |
pGkClient->discoveryComplete = FALSE; |
| 1314 |
pGkClient->state = GkClientIdle; |
| 1315 |
pGkClient->rrqRetries = 0; |
| 1316 |
pGkClient->grqRetries = 0; |
| 1317 |
if(OO_OK != ooGkClientSendGRQ(pGkClient)) |
| 1318 |
{ |
| 1319 |
OOTRACEERR1("Error:Failed to send GRQ message\n"); |
| 1320 |
return OO_FAILED; |
| 1321 |
} |
| 1322 |
return OO_OK; |
| 1323 |
case T_H225RegistrationRejectReason_invalidRevision: |
| 1324 |
OOTRACEERR1("RRQ Rejected - Invalid Revision\n"); |
| 1325 |
break; |
| 1326 |
case T_H225RegistrationRejectReason_invalidCallSignalAddress: |
| 1327 |
OOTRACEERR1("RRQ Rejected - Invalid CallSignalAddress\n"); |
| 1328 |
break; |
| 1329 |
case T_H225RegistrationRejectReason_invalidRASAddress: |
| 1330 |
OOTRACEERR1("RRQ Rejected - Invalid RAS Address\n"); |
| 1331 |
break; |
| 1332 |
case T_H225RegistrationRejectReason_duplicateAlias: |
| 1333 |
OOTRACEERR1("RRQ Rejected - Duplicate Alias\n"); |
| 1334 |
break; |
| 1335 |
case T_H225RegistrationRejectReason_invalidTerminalType: |
| 1336 |
OOTRACEERR1("RRQ Rejected - Invalid Terminal Type\n"); |
| 1337 |
break; |
| 1338 |
case T_H225RegistrationRejectReason_undefinedReason: |
| 1339 |
OOTRACEERR1("RRQ Rejected - Undefined Reason\n"); |
| 1340 |
break; |
| 1341 |
case T_H225RegistrationRejectReason_transportNotSupported: |
| 1342 |
OOTRACEERR1("RRQ Rejected - Transport Not supported\n"); |
| 1343 |
break; |
| 1344 |
case T_H225RegistrationRejectReason_transportQOSNotSupported: |
| 1345 |
OOTRACEERR1("RRQ Rejected - Transport QOS Not Supported\n"); |
| 1346 |
break; |
| 1347 |
case T_H225RegistrationRejectReason_resourceUnavailable: |
| 1348 |
OOTRACEERR1("RRQ Rejected - Resource Unavailable\n"); |
| 1349 |
break; |
| 1350 |
case T_H225RegistrationRejectReason_invalidAlias: |
| 1351 |
OOTRACEERR1("RRQ Rejected - Invalid Alias\n"); |
| 1352 |
break; |
| 1353 |
case T_H225RegistrationRejectReason_securityDenial: |
| 1354 |
OOTRACEERR1("RRQ Rejected - Security Denial\n"); |
| 1355 |
break; |
| 1356 |
case T_H225RegistrationRejectReason_fullRegistrationRequired: |
| 1357 |
OOTRACEINFO1("RRQ Rejected - Full Registration Required\n"); |
| 1358 |
pGkClient->state = GkClientDiscovered; |
| 1359 |
pGkClient->rrqRetries = 0; |
| 1360 |
iRet = ooGkClientSendRRQ(pGkClient, 0); |
| 1361 |
if(iRet != OO_OK){ |
| 1362 |
OOTRACEERR1("\nError: Full Registration transmission failed\n"); |
| 1363 |
return OO_FAILED; |
| 1364 |
} |
| 1365 |
return OO_OK; |
| 1366 |
case T_H225RegistrationRejectReason_additiveRegistrationNotSupported: |
| 1367 |
OOTRACEERR1("RRQ Rejected - Additive Registration Not Supported\n"); |
| 1368 |
break; |
| 1369 |
case T_H225RegistrationRejectReason_invalidTerminalAliases: |
| 1370 |
OOTRACEERR1("RRQ Rejected - Invalid Terminal Aliases\n"); |
| 1371 |
break; |
| 1372 |
case T_H225RegistrationRejectReason_genericDataReason: |
| 1373 |
OOTRACEERR1("RRQ Rejected - Generic Data Reason\n"); |
| 1374 |
break; |
| 1375 |
case T_H225RegistrationRejectReason_neededFeatureNotSupported: |
| 1376 |
OOTRACEERR1("RRQ Rejected - Needed Feature Not Supported\n"); |
| 1377 |
break; |
| 1378 |
case T_H225RegistrationRejectReason_securityError: |
| 1379 |
OOTRACEERR1("RRQ Rejected - Security Error\n"); |
| 1380 |
break; |
| 1381 |
default: |
| 1382 |
OOTRACEINFO1("RRQ Rejected - Invalid Reason\n"); |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
ast_mutex_lock(&pGkClient->Lock); |
| 1387 |
pGkClient->state = GkClientUnregistered; |
| 1388 |
pGkClient->rrqRetries = 0; |
| 1389 |
pGkClient->grqRetries = 0; |
| 1390 |
pGkClient->discoveryComplete = FALSE; |
| 1391 |
|
| 1392 |
cbData = (ooGkClientTimerCb*) memAlloc |
| 1393 |
(&pGkClient->ctxt, sizeof(ooGkClientTimerCb)); |
| 1394 |
if(!cbData) |
| 1395 |
{ |
| 1396 |
OOTRACEERR1("Error:Failed to allocate memory to GRQ timer callback\n"); |
| 1397 |
pGkClient->state = GkClientFailed; |
| 1398 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1399 |
return OO_FAILED; |
| 1400 |
} |
| 1401 |
cbData->timerType = OO_GRQ_TIMER; |
| 1402 |
cbData->pGkClient = pGkClient; |
| 1403 |
if(!ooTimerCreate(&pGkClient->ctxt, &pGkClient->timerList, |
| 1404 |
&ooGkClientGRQTimerExpired, pGkClient->grqTimeout, |
| 1405 |
cbData, FALSE)) |
| 1406 |
{ |
| 1407 |
OOTRACEERR1("Error:Unable to create GRQ timer.\n "); |
| 1408 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 1409 |
pGkClient->state = GkClientFailed; |
| 1410 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1411 |
return OO_FAILED; |
| 1412 |
} |
| 1413 |
|
| 1414 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1415 |
|
| 1416 |
return OO_OK; |
| 1417 |
|
| 1418 |
} |
| 1419 |
|
| 1420 |
|
| 1421 |
int ooGkClientSendURQ(ooGkClient *pGkClient, ooAliases *aliases) |
| 1422 |
{ |
| 1423 |
int iRet; |
| 1424 |
H225RasMessage *pRasMsg=NULL; |
| 1425 |
H225UnregistrationRequest *pUnregReq=NULL; |
| 1426 |
OOCTXT *pctxt=NULL; |
| 1427 |
H225TransportAddress *pTransportAddress=NULL; |
| 1428 |
H225TransportAddress_ipAddress *pIpAddress=NULL; |
| 1429 |
|
| 1430 |
ast_mutex_lock(&pGkClient->Lock); |
| 1431 |
pctxt = &pGkClient->msgCtxt; |
| 1432 |
|
| 1433 |
OOTRACEDBGA1("Building Unregistration Request message\n"); |
| 1434 |
|
| 1435 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 1436 |
if(!pRasMsg) |
| 1437 |
{ |
| 1438 |
OOTRACEERR1("Error: Memory allocation for URQ RAS message failed\n"); |
| 1439 |
pGkClient->state = GkClientFailed; |
| 1440 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1441 |
return OO_FAILED; |
| 1442 |
} |
| 1443 |
|
| 1444 |
pUnregReq = (H225UnregistrationRequest*)memAlloc(pctxt, |
| 1445 |
sizeof(H225UnregistrationRequest)); |
| 1446 |
if(!pUnregReq) |
| 1447 |
{ |
| 1448 |
OOTRACEERR1("Error:Memory allocation for URQ failed\n"); |
| 1449 |
memReset(pctxt); |
| 1450 |
pGkClient->state = GkClientFailed; |
| 1451 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1452 |
return OO_FAILED; |
| 1453 |
} |
| 1454 |
memset(pUnregReq, 0, sizeof(H225UnregistrationRequest)); |
| 1455 |
pRasMsg->t = T_H225RasMessage_unregistrationRequest; |
| 1456 |
pRasMsg->u.unregistrationRequest = pUnregReq; |
| 1457 |
|
| 1458 |
pUnregReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 1459 |
if(!pUnregReq->requestSeqNum) |
| 1460 |
pUnregReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
pTransportAddress = (H225TransportAddress*) memAlloc(pctxt, |
| 1466 |
sizeof(H225TransportAddress)); |
| 1467 |
pIpAddress = (H225TransportAddress_ipAddress*) memAlloc(pctxt, |
| 1468 |
sizeof(H225TransportAddress_ipAddress)); |
| 1469 |
if(!pTransportAddress || !pIpAddress) |
| 1470 |
{ |
| 1471 |
OOTRACEERR1("Error:Failed to allocate memory for signalling address of " |
| 1472 |
"RRQ message\n"); |
| 1473 |
memReset(pctxt); |
| 1474 |
pGkClient->state = GkClientFailed; |
| 1475 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1476 |
return OO_FAILED; |
| 1477 |
} |
| 1478 |
pTransportAddress->t = T_H225TransportAddress_ipAddress; |
| 1479 |
pTransportAddress->u.ipAddress = pIpAddress; |
| 1480 |
inet_pton(AF_INET, pGkClient->localRASIP, pIpAddress->ip.data); |
| 1481 |
pIpAddress->ip.numocts = 4; |
| 1482 |
pIpAddress->port = gH323ep.listenPort; |
| 1483 |
|
| 1484 |
dListInit(&pUnregReq->callSignalAddress); |
| 1485 |
dListAppend(pctxt, &pUnregReq->callSignalAddress, |
| 1486 |
(void*)pTransportAddress); |
| 1487 |
|
| 1488 |
|
| 1489 |
pUnregReq->m.endpointIdentifierPresent = TRUE; |
| 1490 |
pUnregReq->endpointIdentifier.nchars = pGkClient->endpointId.nchars; |
| 1491 |
pUnregReq->endpointIdentifier.data = (ASN116BITCHAR*)memAlloc(pctxt, |
| 1492 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 1493 |
if(!pUnregReq->endpointIdentifier.data) |
| 1494 |
{ |
| 1495 |
OOTRACEERR1("Error: Failed to allocate memory for EndPoint Id in URQ " |
| 1496 |
"message.\n"); |
| 1497 |
memReset(pctxt); |
| 1498 |
pGkClient->state = GkClientFailed; |
| 1499 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1500 |
return OO_FAILED; |
| 1501 |
} |
| 1502 |
memcpy((void*)pUnregReq->endpointIdentifier.data, |
| 1503 |
(void*)pGkClient->endpointId.data, |
| 1504 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 1505 |
|
| 1506 |
|
| 1507 |
if (pGkClient->gkId.nchars) { |
| 1508 |
pUnregReq->m.gatekeeperIdentifierPresent = TRUE; |
| 1509 |
pUnregReq->gatekeeperIdentifier.nchars = pGkClient->gkId.nchars; |
| 1510 |
pUnregReq->gatekeeperIdentifier.data = (ASN116BITCHAR*)memAlloc(pctxt, |
| 1511 |
sizeof(ASN116BITCHAR)*pGkClient->gkId.nchars); |
| 1512 |
if(!pUnregReq->gatekeeperIdentifier.data) |
| 1513 |
{ |
| 1514 |
OOTRACEERR1("Error:Failed to allocate memory for GKID of URQ message\n"); |
| 1515 |
memReset(pctxt); |
| 1516 |
pGkClient->state = GkClientFailed; |
| 1517 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1518 |
return OO_FAILED; |
| 1519 |
} |
| 1520 |
memcpy((void*)pUnregReq->gatekeeperIdentifier.data, |
| 1521 |
(void*)pGkClient->gkId.data, |
| 1522 |
sizeof(ASN116BITCHAR)*pGkClient->gkId.nchars); |
| 1523 |
} |
| 1524 |
|
| 1525 |
|
| 1526 |
if(aliases) |
| 1527 |
{ |
| 1528 |
pUnregReq->m.endpointAliasPresent = TRUE; |
| 1529 |
ooPopulateAliasList(pctxt, aliases, &pUnregReq->endpointAlias, 0); |
| 1530 |
} |
| 1531 |
|
| 1532 |
|
| 1533 |
iRet = ooGkClientSendMsg(pGkClient, pRasMsg); |
| 1534 |
if(iRet != OO_OK) |
| 1535 |
{ |
| 1536 |
OOTRACEERR1("Error:Failed to send UnregistrationRequest message\n"); |
| 1537 |
memReset(pctxt); |
| 1538 |
pGkClient->state = GkClientGkErr; |
| 1539 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1540 |
return OO_FAILED; |
| 1541 |
} |
| 1542 |
pGkClient->state = GkClientUnregistered; |
| 1543 |
OOTRACEINFO1("Unregistration Request message sent.\n"); |
| 1544 |
|
| 1545 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1546 |
return OO_OK; |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
int ooGkClientHandleUnregistrationRequest |
| 1552 |
(ooGkClient *pGkClient, H225UnregistrationRequest * punregistrationRequest) |
| 1553 |
{ |
| 1554 |
int iRet=0, x; |
| 1555 |
OOTimer *pTimer = NULL; |
| 1556 |
DListNode *pNode = NULL; |
| 1557 |
|
| 1558 |
|
| 1559 |
ooGkClientSendUnregistrationConfirm(pGkClient, |
| 1560 |
punregistrationRequest->requestSeqNum); |
| 1561 |
|
| 1562 |
if(punregistrationRequest->m.endpointAliasPresent) |
| 1563 |
{ |
| 1564 |
OOTRACEINFO1("Gatekeeper requested a list of aliases be unregistered\n"); |
| 1565 |
ooGkClientUpdateRegisteredAliases(pGkClient, |
| 1566 |
&punregistrationRequest->endpointAlias, FALSE); |
| 1567 |
} |
| 1568 |
else{ |
| 1569 |
|
| 1570 |
OOTRACEINFO1("Gatekeeper requested a all aliases to be unregistered\n"); |
| 1571 |
ooGkClientUpdateRegisteredAliases(pGkClient, NULL, FALSE); |
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
OOTRACEINFO1("Sending fresh RRQ - as unregistration request received\n"); |
| 1576 |
pGkClient->rrqRetries = 0; |
| 1577 |
pGkClient->state = GkClientDiscovered; |
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
pNode = NULL; |
| 1582 |
for(x=0; x<pGkClient->timerList.count; x++) { |
| 1583 |
pNode = dListFindByIndex(&pGkClient->timerList, x); |
| 1584 |
pTimer = (OOTimer*)pNode->data; |
| 1585 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_RRQ_TIMER) { |
| 1586 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 1587 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer); |
| 1588 |
OOTRACEDBGA1("Deleted RRQ Timer.\n"); |
| 1589 |
} |
| 1590 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_REG_TIMER) { |
| 1591 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 1592 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer); |
| 1593 |
OOTRACEDBGA1("Deleted REG Timer.\n"); |
| 1594 |
} |
| 1595 |
} |
| 1596 |
|
| 1597 |
iRet = ooGkClientSendRRQ(pGkClient, 0); |
| 1598 |
if(iRet != OO_OK) |
| 1599 |
{ |
| 1600 |
OOTRACEERR1("Error: Failed to send RRQ message\n"); |
| 1601 |
return OO_FAILED; |
| 1602 |
} |
| 1603 |
} |
| 1604 |
|
| 1605 |
|
| 1606 |
if(pGkClient->callbacks.onReceivedUnregistrationRequest) |
| 1607 |
pGkClient->callbacks.onReceivedUnregistrationRequest( |
| 1608 |
punregistrationRequest, gH323ep.aliases); |
| 1609 |
return OO_OK; |
| 1610 |
} |
| 1611 |
|
| 1612 |
int ooGkClientSendUnregistrationConfirm(ooGkClient *pGkClient, unsigned reqNo) |
| 1613 |
{ |
| 1614 |
int iRet = OO_OK; |
| 1615 |
OOCTXT *pctxt = &pGkClient->msgCtxt; |
| 1616 |
H225RasMessage *pRasMsg=NULL; |
| 1617 |
H225UnregistrationConfirm *pUCF=NULL; |
| 1618 |
|
| 1619 |
ast_mutex_lock(&pGkClient->Lock); |
| 1620 |
|
| 1621 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 1622 |
pUCF = (H225UnregistrationConfirm*)memAlloc(pctxt, |
| 1623 |
sizeof(H225UnregistrationConfirm)); |
| 1624 |
if(!pRasMsg || !pUCF) |
| 1625 |
{ |
| 1626 |
OOTRACEERR1("Error: Memory allocation for UCF RAS message failed\n"); |
| 1627 |
pGkClient->state = GkClientFailed; |
| 1628 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1629 |
return OO_FAILED; |
| 1630 |
} |
| 1631 |
pRasMsg->t = T_H225RasMessage_unregistrationConfirm; |
| 1632 |
pRasMsg->u.unregistrationConfirm = pUCF; |
| 1633 |
memset(pUCF, 0, sizeof(H225UnregistrationConfirm)); |
| 1634 |
|
| 1635 |
pUCF->requestSeqNum = reqNo; |
| 1636 |
|
| 1637 |
iRet = ooGkClientSendMsg(pGkClient, pRasMsg); |
| 1638 |
if(iRet != OO_OK) |
| 1639 |
{ |
| 1640 |
OOTRACEERR1("Error:Failed to send UnregistrationConfirm message\n"); |
| 1641 |
memReset(pctxt); |
| 1642 |
pGkClient->state = GkClientFailed; |
| 1643 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1644 |
return OO_FAILED; |
| 1645 |
} |
| 1646 |
OOTRACEINFO1("Unregistration Confirm message sent for \n"); |
| 1647 |
memReset(pctxt); |
| 1648 |
|
| 1649 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1650 |
return OO_OK; |
| 1651 |
} |
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
int ooGkClientSendAdmissionRequest |
| 1657 |
(ooGkClient *pGkClient, OOH323CallData *call, ASN1BOOL retransmit) |
| 1658 |
{ |
| 1659 |
int iRet = 0; |
| 1660 |
unsigned int x; |
| 1661 |
DListNode *pNode; |
| 1662 |
ooGkClientTimerCb *cbData=NULL; |
| 1663 |
H225RasMessage *pRasMsg=NULL; |
| 1664 |
OOCTXT* pctxt; |
| 1665 |
H225AdmissionRequest *pAdmReq=NULL; |
| 1666 |
H225TransportAddress_ipAddress *pIpAddressLocal =NULL, *pIpAddressRemote=NULL; |
| 1667 |
ooAliases *destAliases = NULL, *srcAliases=NULL; |
| 1668 |
RasCallAdmissionInfo *pCallAdmInfo=NULL; |
| 1669 |
pctxt = &pGkClient->msgCtxt; |
| 1670 |
|
| 1671 |
ast_mutex_lock(&pGkClient->Lock); |
| 1672 |
|
| 1673 |
OOTRACEDBGA3("Building Admission Request for call (%s, %s)\n", |
| 1674 |
call->callType, call->callToken); |
| 1675 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 1676 |
if(!pRasMsg) |
| 1677 |
{ |
| 1678 |
OOTRACEERR3("Error:Memory - ooGkClientSendAdmissionRequest - " |
| 1679 |
"pRasMsg(%s, %s)\n", call->callType, call->callToken); |
| 1680 |
pGkClient->state = GkClientFailed; |
| 1681 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1682 |
return OO_FAILED; |
| 1683 |
} |
| 1684 |
pRasMsg->t = T_H225RasMessage_admissionRequest; |
| 1685 |
pAdmReq = (H225AdmissionRequest*) memAlloc(pctxt, |
| 1686 |
sizeof(H225AdmissionRequest)); |
| 1687 |
if(!pAdmReq) |
| 1688 |
{ |
| 1689 |
OOTRACEERR3("Error:Memory - ooGkClientSendAdmissionRequest - " |
| 1690 |
"pAdmReq(%s, %s)\n", call->callType, call->callToken); |
| 1691 |
memReset(pctxt); |
| 1692 |
pGkClient->state = GkClientFailed; |
| 1693 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1694 |
return OO_FAILED; |
| 1695 |
} |
| 1696 |
memset(pAdmReq, 0, sizeof(H225AdmissionRequest)); |
| 1697 |
pRasMsg->u.admissionRequest = pAdmReq; |
| 1698 |
|
| 1699 |
|
| 1700 |
pIpAddressLocal = (H225TransportAddress_ipAddress*)memAlloc(pctxt, |
| 1701 |
sizeof(H225TransportAddress_ipAddress)); |
| 1702 |
if(!ooUtilsIsStrEmpty(call->remoteIP)) |
| 1703 |
pIpAddressRemote = (H225TransportAddress_ipAddress*)memAlloc(pctxt, |
| 1704 |
sizeof(H225TransportAddress_ipAddress)); |
| 1705 |
|
| 1706 |
if(!pIpAddressLocal || (!ooUtilsIsStrEmpty(call->remoteIP) && (!pIpAddressRemote))) |
| 1707 |
{ |
| 1708 |
OOTRACEERR1("Error:Failed to allocate memory for Call Signalling " |
| 1709 |
"Addresses of ARQ message\n"); |
| 1710 |
memReset(pctxt); |
| 1711 |
pGkClient->state = GkClientFailed; |
| 1712 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1713 |
return OO_FAILED; |
| 1714 |
} |
| 1715 |
inet_pton(AF_INET, pGkClient->localRASIP, pIpAddressLocal->ip.data); |
| 1716 |
|
| 1717 |
pIpAddressLocal->ip.numocts = 4; |
| 1718 |
pIpAddressLocal->port = gH323ep.listenPort; |
| 1719 |
|
| 1720 |
if(!ooUtilsIsStrEmpty(call->remoteIP)) |
| 1721 |
{ |
| 1722 |
inet_pton(AF_INET, call->remoteIP, pIpAddressRemote->ip.data); |
| 1723 |
pIpAddressRemote->ip.numocts = 4; |
| 1724 |
pIpAddressRemote->port = call->remotePort; |
| 1725 |
} |
| 1726 |
|
| 1727 |
if(!strcmp(call->callType, "incoming")) |
| 1728 |
{ |
| 1729 |
pAdmReq->m.destCallSignalAddressPresent = TRUE; |
| 1730 |
pAdmReq->destCallSignalAddress.t = T_H225TransportAddress_ipAddress; |
| 1731 |
pAdmReq->destCallSignalAddress.u.ipAddress = pIpAddressLocal; |
| 1732 |
if(!ooUtilsIsStrEmpty(call->remoteIP)) |
| 1733 |
{ |
| 1734 |
pAdmReq->m.srcCallSignalAddressPresent = TRUE; |
| 1735 |
pAdmReq->srcCallSignalAddress.t = T_H225TransportAddress_ipAddress; |
| 1736 |
pAdmReq->srcCallSignalAddress.u.ipAddress = pIpAddressRemote; |
| 1737 |
} |
| 1738 |
} |
| 1739 |
else { |
| 1740 |
pAdmReq->m.srcCallSignalAddressPresent = TRUE; |
| 1741 |
pAdmReq->srcCallSignalAddress.t = T_H225TransportAddress_ipAddress; |
| 1742 |
pAdmReq->srcCallSignalAddress.u.ipAddress = pIpAddressLocal; |
| 1743 |
if(!ooUtilsIsStrEmpty(call->remoteIP)) |
| 1744 |
{ |
| 1745 |
pAdmReq->m.destCallSignalAddressPresent = TRUE; |
| 1746 |
pAdmReq->destCallSignalAddress.t = T_H225TransportAddress_ipAddress; |
| 1747 |
pAdmReq->destCallSignalAddress.u.ipAddress = pIpAddressRemote; |
| 1748 |
} |
| 1749 |
} |
| 1750 |
|
| 1751 |
|
| 1752 |
pAdmReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 1753 |
if(!pAdmReq->requestSeqNum) |
| 1754 |
pAdmReq->requestSeqNum = pGkClient->requestSeqNum++; |
| 1755 |
|
| 1756 |
|
| 1757 |
pAdmReq->callType.t = T_H225CallType_pointToPoint; |
| 1758 |
|
| 1759 |
|
| 1760 |
pAdmReq->m.callModelPresent = 1; |
| 1761 |
if(OO_TESTFLAG(call->flags, OO_M_GKROUTED)) |
| 1762 |
pAdmReq->callModel.t = T_H225CallModel_gatekeeperRouted; |
| 1763 |
else |
| 1764 |
pAdmReq->callModel.t = T_H225CallModel_direct; |
| 1765 |
|
| 1766 |
|
| 1767 |
pAdmReq->endpointIdentifier.nchars = pGkClient->endpointId.nchars; |
| 1768 |
pAdmReq->endpointIdentifier.data = (ASN116BITCHAR*)memAlloc(pctxt, |
| 1769 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 1770 |
if(!pAdmReq->endpointIdentifier.data) |
| 1771 |
{ |
| 1772 |
OOTRACEERR3("Error:Memory - ooGkClientSendAdmissionRequest - " |
| 1773 |
"endpointIdentifier.data(%s, %s)\n", call->callType, |
| 1774 |
call->callToken); |
| 1775 |
memReset(pctxt); |
| 1776 |
pGkClient->state = GkClientFailed; |
| 1777 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1778 |
return OO_FAILED; |
| 1779 |
} |
| 1780 |
memcpy((void*)pAdmReq->endpointIdentifier.data, |
| 1781 |
(void*)pGkClient->endpointId.data, |
| 1782 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 1783 |
|
| 1784 |
|
| 1785 |
if(!strcmp(call->callType, "incoming")) |
| 1786 |
{ |
| 1787 |
if(call->ourAliases) |
| 1788 |
destAliases = call->ourAliases; |
| 1789 |
else |
| 1790 |
destAliases = gH323ep.aliases; |
| 1791 |
|
| 1792 |
srcAliases = call->remoteAliases; |
| 1793 |
} |
| 1794 |
else { |
| 1795 |
if(call->ourAliases) |
| 1796 |
srcAliases = call->ourAliases; |
| 1797 |
else |
| 1798 |
srcAliases = gH323ep.aliases; |
| 1799 |
|
| 1800 |
destAliases = call->remoteAliases; |
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
if(destAliases) |
| 1805 |
{ |
| 1806 |
pAdmReq->m.destinationInfoPresent = 1; |
| 1807 |
if(OO_OK != ooPopulateAliasList(&pGkClient->msgCtxt, destAliases, |
| 1808 |
&pAdmReq->destinationInfo, T_H225AliasAddress_dialedDigits)) |
| 1809 |
{ |
| 1810 |
OOTRACEERR1("Error:Failed to populate destination aliases - " |
| 1811 |
"ARQ message\n"); |
| 1812 |
pGkClient->state = GkClientFailed; |
| 1813 |
memReset(pctxt); |
| 1814 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1815 |
return OO_FAILED; |
| 1816 |
} |
| 1817 |
} |
| 1818 |
|
| 1819 |
|
| 1820 |
if(srcAliases) |
| 1821 |
{ |
| 1822 |
iRet = ooPopulateAliasList(&pGkClient->msgCtxt, srcAliases, |
| 1823 |
&pAdmReq->srcInfo, 0); |
| 1824 |
if(OO_OK != iRet) |
| 1825 |
{ |
| 1826 |
OOTRACEERR1("Error:Failed to populate source aliases -ARQ message\n"); |
| 1827 |
memReset(pctxt); |
| 1828 |
pGkClient->state = GkClientFailed; |
| 1829 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1830 |
return OO_FAILED; |
| 1831 |
} |
| 1832 |
} |
| 1833 |
|
| 1834 |
|
| 1835 |
pAdmReq->bandWidth = DEFAULT_BW_REQUEST; |
| 1836 |
|
| 1837 |
pAdmReq->callReferenceValue = call->callReference; |
| 1838 |
|
| 1839 |
|
| 1840 |
memcpy((void*)&pAdmReq->conferenceID, (void*)&call->confIdentifier, |
| 1841 |
sizeof(H225ConferenceIdentifier)); |
| 1842 |
|
| 1843 |
if(!strcmp(call->callType, "incoming")) |
| 1844 |
pAdmReq->answerCall = TRUE; |
| 1845 |
else |
| 1846 |
pAdmReq->answerCall = FALSE; |
| 1847 |
|
| 1848 |
|
| 1849 |
pAdmReq->m.canMapAliasPresent = TRUE; |
| 1850 |
pAdmReq->canMapAlias = FALSE; |
| 1851 |
|
| 1852 |
|
| 1853 |
pAdmReq->m.callIdentifierPresent = TRUE; |
| 1854 |
memcpy((void*)&pAdmReq->callIdentifier, (void*)&call->callIdentifier, |
| 1855 |
sizeof(H225CallIdentifier)); |
| 1856 |
|
| 1857 |
|
| 1858 |
if (pGkClient->gkId.nchars) { |
| 1859 |
pAdmReq->m.gatekeeperIdentifierPresent = TRUE; |
| 1860 |
pAdmReq->gatekeeperIdentifier.nchars = pGkClient->gkId.nchars; |
| 1861 |
pAdmReq->gatekeeperIdentifier.data = (ASN116BITCHAR*)memAlloc(pctxt, |
| 1862 |
sizeof(ASN116BITCHAR)*pGkClient->gkId.nchars); |
| 1863 |
if(!pAdmReq->gatekeeperIdentifier.data) |
| 1864 |
{ |
| 1865 |
OOTRACEERR1("Error:Failed to allocate memory for GKID of ARQ message\n"); |
| 1866 |
memReset(pctxt); |
| 1867 |
pGkClient->state = GkClientFailed; |
| 1868 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1869 |
return OO_FAILED; |
| 1870 |
} |
| 1871 |
memcpy((void*)pAdmReq->gatekeeperIdentifier.data, |
| 1872 |
(void*)pGkClient->gkId.data, |
| 1873 |
sizeof(ASN116BITCHAR)*pGkClient->gkId.nchars); |
| 1874 |
} |
| 1875 |
|
| 1876 |
pAdmReq->m.willSupplyUUIEsPresent = 1; |
| 1877 |
pAdmReq->willSupplyUUIEs = FALSE; |
| 1878 |
|
| 1879 |
|
| 1880 |
if(!retransmit) |
| 1881 |
{ |
| 1882 |
pCallAdmInfo = (RasCallAdmissionInfo*)memAlloc(&pGkClient->ctxt, |
| 1883 |
sizeof(RasCallAdmissionInfo)); |
| 1884 |
if(!pCallAdmInfo) |
| 1885 |
{ |
| 1886 |
OOTRACEERR1("Error: Failed to allocate memory for new CallAdmission" |
| 1887 |
" Info entry\n"); |
| 1888 |
memReset(pctxt); |
| 1889 |
pGkClient->state = GkClientFailed; |
| 1890 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1891 |
return OO_FAILED; |
| 1892 |
} |
| 1893 |
|
| 1894 |
pCallAdmInfo->call = call; |
| 1895 |
pCallAdmInfo->retries = 0; |
| 1896 |
pCallAdmInfo->requestSeqNum = pAdmReq->requestSeqNum; |
| 1897 |
dListAppend(&pGkClient->ctxt, &pGkClient->callsPendingList,pCallAdmInfo); |
| 1898 |
} |
| 1899 |
else{ |
| 1900 |
for(x=0; x<pGkClient->callsPendingList.count; x++) |
| 1901 |
{ |
| 1902 |
pNode = dListFindByIndex(&pGkClient->callsPendingList, x); |
| 1903 |
pCallAdmInfo = (RasCallAdmissionInfo*)pNode->data; |
| 1904 |
if(pCallAdmInfo->call->callReference == call->callReference) |
| 1905 |
{ |
| 1906 |
pCallAdmInfo->requestSeqNum = pAdmReq->requestSeqNum; |
| 1907 |
break; |
| 1908 |
} |
| 1909 |
} |
| 1910 |
} |
| 1911 |
|
| 1912 |
iRet = ooGkClientSendMsg(pGkClient, pRasMsg); |
| 1913 |
if(iRet != OO_OK) |
| 1914 |
{ |
| 1915 |
OOTRACEERR1("Error:Failed to send AdmissionRequest message\n"); |
| 1916 |
memReset(pctxt); |
| 1917 |
pGkClient->state = GkClientGkErr; |
| 1918 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1919 |
return OO_FAILED; |
| 1920 |
} |
| 1921 |
OOTRACEINFO3("Admission Request message sent for (%s, %s)\n", |
| 1922 |
call->callType, call->callToken); |
| 1923 |
memReset(pctxt); |
| 1924 |
|
| 1925 |
|
| 1926 |
cbData = (ooGkClientTimerCb*) memAlloc |
| 1927 |
(&pGkClient->ctxt, sizeof(ooGkClientTimerCb)); |
| 1928 |
if(!cbData) |
| 1929 |
{ |
| 1930 |
OOTRACEERR1("Error:Failed to allocate memory for Registration timer." |
| 1931 |
"\n"); |
| 1932 |
pGkClient->state = GkClientFailed; |
| 1933 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1934 |
return OO_FAILED; |
| 1935 |
} |
| 1936 |
cbData->timerType = OO_ARQ_TIMER; |
| 1937 |
cbData->pGkClient = pGkClient; |
| 1938 |
cbData->pAdmInfo = pCallAdmInfo; |
| 1939 |
if(!ooTimerCreate(&pGkClient->ctxt, &pGkClient->timerList, |
| 1940 |
&ooGkClientARQTimerExpired, pGkClient->arqTimeout, |
| 1941 |
cbData, FALSE)) |
| 1942 |
{ |
| 1943 |
OOTRACEERR1("Error:Unable to create ARQ timer.\n "); |
| 1944 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 1945 |
pGkClient->state = GkClientFailed; |
| 1946 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1947 |
return OO_FAILED; |
| 1948 |
} |
| 1949 |
|
| 1950 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1951 |
return OO_OK; |
| 1952 |
} |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
int ooGkClientHandleAdmissionConfirm |
| 1959 |
(ooGkClient *pGkClient, H225AdmissionConfirm *pAdmissionConfirm) |
| 1960 |
{ |
| 1961 |
RasCallAdmissionInfo* pCallAdmInfo=NULL; |
| 1962 |
unsigned int x, y; |
| 1963 |
DListNode *pNode, *pNode1=NULL; |
| 1964 |
H225TransportAddress_ipAddress * ipAddress=NULL; |
| 1965 |
OOTimer *pTimer = NULL; |
| 1966 |
char ip[20]; |
| 1967 |
|
| 1968 |
ast_mutex_lock(&pGkClient->Lock); |
| 1969 |
|
| 1970 |
|
| 1971 |
for(x=0 ; x<pGkClient->callsPendingList.count; x++) |
| 1972 |
{ |
| 1973 |
pNode = dListFindByIndex(&pGkClient->callsPendingList, x); |
| 1974 |
pCallAdmInfo = (RasCallAdmissionInfo*) pNode->data; |
| 1975 |
if(pCallAdmInfo->requestSeqNum == pAdmissionConfirm->requestSeqNum) |
| 1976 |
{ |
| 1977 |
OOTRACEDBGC3("Found Pending call(%s, %s)\n", |
| 1978 |
pCallAdmInfo->call->callType, |
| 1979 |
pCallAdmInfo->call->callToken); |
| 1980 |
|
| 1981 |
ast_mutex_lock(&pCallAdmInfo->call->GkLock); |
| 1982 |
|
| 1983 |
|
| 1984 |
if(pAdmissionConfirm->destCallSignalAddress.t != |
| 1985 |
T_H225TransportAddress_ipAddress) |
| 1986 |
{ |
| 1987 |
OOTRACEERR1("Error:Destination Call Signal Address provided by" |
| 1988 |
"Gatekeeper is not an IPv4 address\n"); |
| 1989 |
OOTRACEINFO1("Ignoring ACF, will wait for timeout and retransmit " |
| 1990 |
"ARQ\n"); |
| 1991 |
ast_mutex_unlock(&pCallAdmInfo->call->GkLock); |
| 1992 |
ast_mutex_unlock(&pGkClient->Lock); |
| 1993 |
ast_cond_signal(&pCallAdmInfo->call->gkWait); |
| 1994 |
return OO_FAILED; |
| 1995 |
} |
| 1996 |
ipAddress = pAdmissionConfirm->destCallSignalAddress.u.ipAddress; |
| 1997 |
|
| 1998 |
sprintf(ip, "%d.%d.%d.%d", ipAddress->ip.data[0], |
| 1999 |
ipAddress->ip.data[1], |
| 2000 |
ipAddress->ip.data[2], |
| 2001 |
ipAddress->ip.data[3]); |
| 2002 |
if(strcmp(ip, "0.0.0.0")) { |
| 2003 |
|
| 2004 |
pCallAdmInfo->call->versionIP = 4; |
| 2005 |
strcpy(pCallAdmInfo->call->remoteIP, ip); |
| 2006 |
} |
| 2007 |
pCallAdmInfo->call->remotePort = ipAddress->port; |
| 2008 |
|
| 2009 |
if(pAdmissionConfirm->callModel.t == T_H225CallModel_direct) |
| 2010 |
{ |
| 2011 |
if(OO_TESTFLAG(pCallAdmInfo->call->flags, OO_M_GKROUTED)) |
| 2012 |
{ |
| 2013 |
OOTRACEINFO3("Gatekeeper changed call model from GkRouted to " |
| 2014 |
"direct. (%s, %s)\n", pCallAdmInfo->call->callType, |
| 2015 |
pCallAdmInfo->call->callToken); |
| 2016 |
OO_CLRFLAG(pCallAdmInfo->call->flags, OO_M_GKROUTED); |
| 2017 |
} |
| 2018 |
} |
| 2019 |
|
| 2020 |
if(pAdmissionConfirm->callModel.t == T_H225CallModel_gatekeeperRouted) |
| 2021 |
{ |
| 2022 |
if(!OO_TESTFLAG(pCallAdmInfo->call->flags, OO_M_GKROUTED)) |
| 2023 |
{ |
| 2024 |
OOTRACEINFO3("Gatekeeper changed call model from direct to " |
| 2025 |
"GkRouted. (%s, %s)\n", |
| 2026 |
pCallAdmInfo->call->callType, |
| 2027 |
pCallAdmInfo->call->callToken); |
| 2028 |
OO_SETFLAG(pCallAdmInfo->call->flags, OO_M_GKROUTED); |
| 2029 |
} |
| 2030 |
} |
| 2031 |
|
| 2032 |
|
| 2033 |
for(y=0; y<pGkClient->timerList.count; y++) |
| 2034 |
{ |
| 2035 |
pNode1 = dListFindByIndex(&pGkClient->timerList, y); |
| 2036 |
pTimer = (OOTimer*)pNode1->data; |
| 2037 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_ARQ_TIMER) |
| 2038 |
{ |
| 2039 |
if(((ooGkClientTimerCb*)pTimer->cbData)->pAdmInfo == |
| 2040 |
pCallAdmInfo) |
| 2041 |
{ |
| 2042 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 2043 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, |
| 2044 |
pTimer); |
| 2045 |
OOTRACEDBGA1("Deleted ARQ Timer.\n"); |
| 2046 |
break; |
| 2047 |
} |
| 2048 |
} |
| 2049 |
} |
| 2050 |
OOTRACEINFO3("Admission Confirm message received for (%s, %s)\n", |
| 2051 |
pCallAdmInfo->call->callType, |
| 2052 |
pCallAdmInfo->call->callToken); |
| 2053 |
|
| 2054 |
pCallAdmInfo->call->callState = OO_CALL_CONNECTING; |
| 2055 |
|
| 2056 |
dListRemove(&pGkClient->callsPendingList, pNode); |
| 2057 |
dListAppend(&pGkClient->ctxt, &pGkClient->callsAdmittedList, |
| 2058 |
pNode->data); |
| 2059 |
memFreePtr(&pGkClient->ctxt, pNode); |
| 2060 |
ast_mutex_unlock(&pCallAdmInfo->call->GkLock); |
| 2061 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2062 |
ast_cond_signal(&pCallAdmInfo->call->gkWait); |
| 2063 |
return OO_OK; |
| 2064 |
} |
| 2065 |
else |
| 2066 |
{ |
| 2067 |
pNode = pNode->next; |
| 2068 |
} |
| 2069 |
} |
| 2070 |
OOTRACEERR1("Error: Failed to process ACF as there is no corresponding " |
| 2071 |
"pending call\n"); |
| 2072 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2073 |
return OO_OK; |
| 2074 |
} |
| 2075 |
|
| 2076 |
|
| 2077 |
int ooGkClientHandleAdmissionReject |
| 2078 |
(ooGkClient *pGkClient, H225AdmissionReject *pAdmissionReject) |
| 2079 |
{ |
| 2080 |
RasCallAdmissionInfo* pCallAdmInfo=NULL; |
| 2081 |
unsigned int x, y; |
| 2082 |
DListNode *pNode=NULL, *pNode1=NULL; |
| 2083 |
OOH323CallData *call=NULL; |
| 2084 |
OOTimer *pTimer = NULL; |
| 2085 |
|
| 2086 |
ast_mutex_lock(&pGkClient->Lock); |
| 2087 |
|
| 2088 |
|
| 2089 |
for(x=0 ; x<pGkClient->callsPendingList.count; x++) |
| 2090 |
{ |
| 2091 |
pNode = dListFindByIndex(&pGkClient->callsPendingList, x); |
| 2092 |
pCallAdmInfo = (RasCallAdmissionInfo*) pNode->data; |
| 2093 |
if(pCallAdmInfo->requestSeqNum == pAdmissionReject->requestSeqNum) |
| 2094 |
break; |
| 2095 |
pNode = NULL; |
| 2096 |
pCallAdmInfo = NULL; |
| 2097 |
} |
| 2098 |
|
| 2099 |
if(!pCallAdmInfo) |
| 2100 |
{ |
| 2101 |
OOTRACEWARN2("Received admission reject with request number %d can not" |
| 2102 |
" be matched with any pending call.\n", |
| 2103 |
pAdmissionReject->requestSeqNum); |
| 2104 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2105 |
return OO_OK; |
| 2106 |
} |
| 2107 |
else{ |
| 2108 |
call = pCallAdmInfo->call; |
| 2109 |
dListRemove(&pGkClient->callsPendingList, pNode); |
| 2110 |
memFreePtr(&pGkClient->ctxt, pCallAdmInfo); |
| 2111 |
memFreePtr(&pGkClient->ctxt, pNode); |
| 2112 |
} |
| 2113 |
ast_mutex_lock(&pCallAdmInfo->call->GkLock); |
| 2114 |
|
| 2115 |
|
| 2116 |
for(y=0; y<pGkClient->timerList.count; y++) |
| 2117 |
{ |
| 2118 |
pNode1 = dListFindByIndex(&pGkClient->timerList, y); |
| 2119 |
pTimer = (OOTimer*)pNode1->data; |
| 2120 |
if(((ooGkClientTimerCb*)pTimer->cbData)->timerType & OO_ARQ_TIMER) |
| 2121 |
{ |
| 2122 |
if(((ooGkClientTimerCb*)pTimer->cbData)->pAdmInfo == |
| 2123 |
pCallAdmInfo) |
| 2124 |
{ |
| 2125 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 2126 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, |
| 2127 |
pTimer); |
| 2128 |
OOTRACEDBGA1("Deleted ARQ Timer.\n"); |
| 2129 |
break; |
| 2130 |
} |
| 2131 |
} |
| 2132 |
} |
| 2133 |
OOTRACEINFO4("Admission Reject message received with reason code %d for " |
| 2134 |
"(%s, %s)\n", pAdmissionReject->rejectReason.t, call->callType, |
| 2135 |
call->callToken); |
| 2136 |
|
| 2137 |
call->callState = OO_CALL_CLEARED; |
| 2138 |
|
| 2139 |
switch(pAdmissionReject->rejectReason.t) |
| 2140 |
{ |
| 2141 |
case T_H225AdmissionRejectReason_calledPartyNotRegistered: |
| 2142 |
call->callEndReason = OO_REASON_GK_NOCALLEDUSER; |
| 2143 |
break; |
| 2144 |
case T_H225AdmissionRejectReason_invalidPermission: |
| 2145 |
case T_H225AdmissionRejectReason_requestDenied: |
| 2146 |
case T_H225AdmissionRejectReason_undefinedReason: |
| 2147 |
call->callEndReason = OO_REASON_GK_CLEARED; |
| 2148 |
break; |
| 2149 |
case T_H225AdmissionRejectReason_callerNotRegistered: |
| 2150 |
call->callEndReason = OO_REASON_GK_NOCALLERUSER; |
| 2151 |
break; |
| 2152 |
case T_H225AdmissionRejectReason_exceedsCallCapacity: |
| 2153 |
case T_H225AdmissionRejectReason_resourceUnavailable: |
| 2154 |
call->callEndReason = OO_REASON_GK_NORESOURCES; |
| 2155 |
break; |
| 2156 |
case T_H225AdmissionRejectReason_noRouteToDestination: |
| 2157 |
case T_H225AdmissionRejectReason_unallocatedNumber: |
| 2158 |
call->callEndReason = OO_REASON_GK_UNREACHABLE; |
| 2159 |
break; |
| 2160 |
case T_H225AdmissionRejectReason_routeCallToGatekeeper: |
| 2161 |
case T_H225AdmissionRejectReason_invalidEndpointIdentifier: |
| 2162 |
case T_H225AdmissionRejectReason_securityDenial: |
| 2163 |
case T_H225AdmissionRejectReason_qosControlNotSupported: |
| 2164 |
case T_H225AdmissionRejectReason_incompleteAddress: |
| 2165 |
case T_H225AdmissionRejectReason_aliasesInconsistent: |
| 2166 |
case T_H225AdmissionRejectReason_routeCallToSCN: |
| 2167 |
case T_H225AdmissionRejectReason_collectDestination: |
| 2168 |
case T_H225AdmissionRejectReason_collectPIN: |
| 2169 |
case T_H225AdmissionRejectReason_genericDataReason: |
| 2170 |
case T_H225AdmissionRejectReason_neededFeatureNotSupported: |
| 2171 |
case T_H225AdmissionRejectReason_securityErrors: |
| 2172 |
case T_H225AdmissionRejectReason_securityDHmismatch: |
| 2173 |
case T_H225AdmissionRejectReason_extElem1: |
| 2174 |
call->callEndReason = OO_REASON_GK_CLEARED; |
| 2175 |
break; |
| 2176 |
} |
| 2177 |
|
| 2178 |
ast_mutex_unlock(&pCallAdmInfo->call->GkLock); |
| 2179 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2180 |
ast_cond_signal(&pCallAdmInfo->call->gkWait); |
| 2181 |
return OO_OK; |
| 2182 |
} |
| 2183 |
|
| 2184 |
|
| 2185 |
int ooGkClientSendIRR |
| 2186 |
(ooGkClient *pGkClient, OOH323CallData *call) |
| 2187 |
{ |
| 2188 |
int iRet = 0; |
| 2189 |
H225RasMessage *pRasMsg=NULL; |
| 2190 |
OOCTXT* pctxt; |
| 2191 |
H225InfoRequestResponse *pIRR=NULL; |
| 2192 |
H225TransportAddress_ipAddress *pIpAddressLocal =NULL, *pIpRasAddress, |
| 2193 |
*pLocalAddr, *pRemoteAddr; |
| 2194 |
H225TransportAddress *pTransportAddress; |
| 2195 |
ooAliases *srcAliases=NULL; |
| 2196 |
H225InfoRequestResponse_perCallInfo_element *perCallInfo = NULL; |
| 2197 |
pctxt = &pGkClient->msgCtxt; |
| 2198 |
|
| 2199 |
ast_mutex_lock(&pGkClient->Lock); |
| 2200 |
|
| 2201 |
OOTRACEDBGA3("Building Info Request Resp for call (%s, %s)\n", |
| 2202 |
call->callType, call->callToken); |
| 2203 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 2204 |
if(!pRasMsg) |
| 2205 |
{ |
| 2206 |
OOTRACEERR3("Error:Memory - ooGkClientSendIRR - " |
| 2207 |
"pRasMsg(%s, %s)\n", call->callType, call->callToken); |
| 2208 |
pGkClient->state = GkClientFailed; |
| 2209 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2210 |
return OO_FAILED; |
| 2211 |
} |
| 2212 |
pRasMsg->t = T_H225RasMessage_infoRequestResponse; |
| 2213 |
pIRR = (H225InfoRequestResponse*) memAlloc(pctxt, |
| 2214 |
sizeof(H225InfoRequestResponse)); |
| 2215 |
if(!pIRR) |
| 2216 |
{ |
| 2217 |
OOTRACEERR3("Error:Memory - ooGkClientSendIRR - " |
| 2218 |
"pIRR(%s, %s)\n", call->callType, call->callToken); |
| 2219 |
memReset(pctxt); |
| 2220 |
pGkClient->state = GkClientFailed; |
| 2221 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2222 |
return OO_FAILED; |
| 2223 |
} |
| 2224 |
memset(pIRR, 0, sizeof(H225InfoRequestResponse)); |
| 2225 |
pRasMsg->u.infoRequestResponse = pIRR; |
| 2226 |
|
| 2227 |
|
| 2228 |
pIpAddressLocal = (H225TransportAddress_ipAddress*)memAlloc(pctxt, |
| 2229 |
sizeof(H225TransportAddress_ipAddress)); |
| 2230 |
pTransportAddress = (H225TransportAddress*) memAlloc(pctxt, |
| 2231 |
sizeof(H225TransportAddress)); |
| 2232 |
if(!pIpAddressLocal || !pTransportAddress) |
| 2233 |
{ |
| 2234 |
OOTRACEERR1("Error:Failed to allocate memory for Call Signalling " |
| 2235 |
"Addresses of IRR message\n"); |
| 2236 |
memReset(pctxt); |
| 2237 |
pGkClient->state = GkClientFailed; |
| 2238 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2239 |
return OO_FAILED; |
| 2240 |
} |
| 2241 |
inet_pton(AF_INET, pGkClient->localRASIP, pIpAddressLocal->ip.data); |
| 2242 |
|
| 2243 |
pIpAddressLocal->ip.numocts = 4; |
| 2244 |
pIpAddressLocal->port = gH323ep.listenPort; |
| 2245 |
|
| 2246 |
pTransportAddress->t = T_H225TransportAddress_ipAddress; |
| 2247 |
pTransportAddress->u.ipAddress = pIpAddressLocal; |
| 2248 |
|
| 2249 |
dListInit(&pIRR->callSignalAddress); |
| 2250 |
dListAppend(pctxt, &pIRR->callSignalAddress, |
| 2251 |
(void*)pTransportAddress); |
| 2252 |
|
| 2253 |
|
| 2254 |
pIRR->requestSeqNum = pGkClient->requestSeqNum++; |
| 2255 |
if(!pIRR->requestSeqNum) |
| 2256 |
pIRR->requestSeqNum = pGkClient->requestSeqNum++; |
| 2257 |
|
| 2258 |
pIpRasAddress = (H225TransportAddress_ipAddress*)memAlloc(pctxt, |
| 2259 |
sizeof(H225TransportAddress_ipAddress)); |
| 2260 |
if(!pIpRasAddress) |
| 2261 |
{ |
| 2262 |
OOTRACEERR1("Error: Memory allocation for Ras Address of IRR message " |
| 2263 |
"failed\n"); |
| 2264 |
memReset(&pGkClient->msgCtxt); |
| 2265 |
pGkClient->state = GkClientFailed; |
| 2266 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2267 |
return OO_FAILED; |
| 2268 |
} |
| 2269 |
|
| 2270 |
pIpRasAddress->ip.numocts = 4; |
| 2271 |
pIpRasAddress->port = pGkClient->localRASPort; |
| 2272 |
inet_pton(AF_INET, pGkClient->localRASIP, pIpRasAddress->ip.data); |
| 2273 |
|
| 2274 |
pIRR->rasAddress.u.ipAddress = pIpRasAddress; |
| 2275 |
pIRR->rasAddress.t=T_H225TransportAddress_ipAddress; |
| 2276 |
|
| 2277 |
|
| 2278 |
if(gH323ep.isGateway) |
| 2279 |
pIRR->endpointType.m.gatewayPresent = TRUE; |
| 2280 |
else |
| 2281 |
pIRR->endpointType.m.terminalPresent = TRUE; |
| 2282 |
|
| 2283 |
pIRR->endpointType.m.nonStandardDataPresent=FALSE; |
| 2284 |
pIRR->endpointType.m.vendorPresent=TRUE; |
| 2285 |
ooGkClientFillVendor(pGkClient, &pIRR->endpointType.vendor); |
| 2286 |
|
| 2287 |
|
| 2288 |
pIRR->endpointIdentifier.nchars = pGkClient->endpointId.nchars; |
| 2289 |
pIRR->endpointIdentifier.data = (ASN116BITCHAR*)memAlloc(pctxt, |
| 2290 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 2291 |
if(!pIRR->endpointIdentifier.data) |
| 2292 |
{ |
| 2293 |
OOTRACEERR3("Error:Memory - ooGkClientSendIRR - " |
| 2294 |
"endpointIdentifier.data(%s, %s)\n", call->callType, |
| 2295 |
call->callToken); |
| 2296 |
memReset(pctxt); |
| 2297 |
pGkClient->state = GkClientFailed; |
| 2298 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2299 |
return OO_FAILED; |
| 2300 |
} |
| 2301 |
memcpy((void*)pIRR->endpointIdentifier.data, |
| 2302 |
(void*)pGkClient->endpointId.data, |
| 2303 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
if(call->ourAliases) |
| 2308 |
srcAliases = call->ourAliases; |
| 2309 |
else |
| 2310 |
srcAliases = gH323ep.aliases; |
| 2311 |
|
| 2312 |
|
| 2313 |
if(srcAliases) |
| 2314 |
{ |
| 2315 |
iRet = ooPopulateAliasList(&pGkClient->msgCtxt, srcAliases, |
| 2316 |
&pIRR->endpointAlias, T_H225AliasAddress_h323_ID); |
| 2317 |
if(OO_OK != iRet) |
| 2318 |
{ |
| 2319 |
OOTRACEERR1("Error:Failed to populate source aliases -IRR message\n"); |
| 2320 |
memReset(pctxt); |
| 2321 |
pGkClient->state = GkClientFailed; |
| 2322 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2323 |
return OO_FAILED; |
| 2324 |
} |
| 2325 |
} |
| 2326 |
pIRR->m.endpointAliasPresent = TRUE; |
| 2327 |
|
| 2328 |
|
| 2329 |
pIRR->needResponse = FALSE; |
| 2330 |
pIRR->m.needResponsePresent = TRUE; |
| 2331 |
pIRR->unsolicited = TRUE; |
| 2332 |
pIRR->m.unsolicitedPresent = TRUE; |
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
pIRR->m.perCallInfoPresent = TRUE; |
| 2337 |
|
| 2338 |
perCallInfo = |
| 2339 |
(H225InfoRequestResponse_perCallInfo_element *)memAllocZ(pctxt, |
| 2340 |
sizeof(H225InfoRequestResponse_perCallInfo_element)); |
| 2341 |
|
| 2342 |
if(!perCallInfo) |
| 2343 |
{ |
| 2344 |
OOTRACEERR3("Error:Memory - ooGkClientSendIRR - " |
| 2345 |
"perCallInfo for (%s, %s)\n", call->callType, |
| 2346 |
call->callToken); |
| 2347 |
memReset(pctxt); |
| 2348 |
pGkClient->state = GkClientFailed; |
| 2349 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2350 |
return OO_FAILED; |
| 2351 |
} |
| 2352 |
|
| 2353 |
perCallInfo->m.originatorPresent = TRUE; |
| 2354 |
perCallInfo->originator = (!strcmp(call->callType, "incoming")) ? FALSE : TRUE; |
| 2355 |
|
| 2356 |
pLocalAddr = (H225TransportAddress_ipAddress*)memAlloc(pctxt, |
| 2357 |
sizeof(H225TransportAddress_ipAddress)); |
| 2358 |
pRemoteAddr = (H225TransportAddress_ipAddress*) memAlloc(pctxt, |
| 2359 |
sizeof(H225TransportAddress_ipAddress)); |
| 2360 |
if(!pLocalAddr || !pRemoteAddr) |
| 2361 |
{ |
| 2362 |
OOTRACEERR1("Error:Failed to allocate memory for Call Signalling " |
| 2363 |
"Addresses of IRR message\n"); |
| 2364 |
memReset(pctxt); |
| 2365 |
pGkClient->state = GkClientFailed; |
| 2366 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2367 |
return OO_FAILED; |
| 2368 |
} |
| 2369 |
pLocalAddr->ip.numocts = 4; |
| 2370 |
inet_pton(AF_INET, call->localIP, pLocalAddr->ip.data); |
| 2371 |
pLocalAddr->port = (call->pH225Channel->port) ? call->pH225Channel->port : gH323ep.listenPort; |
| 2372 |
|
| 2373 |
pRemoteAddr->ip.numocts = 4; |
| 2374 |
inet_pton(AF_INET, call->remoteIP, pRemoteAddr->ip.data); |
| 2375 |
pRemoteAddr->port = call->remotePort; |
| 2376 |
|
| 2377 |
perCallInfo->callSignaling.m.sendAddressPresent = TRUE; |
| 2378 |
perCallInfo->callSignaling.sendAddress.t = T_H225TransportAddress_ipAddress; |
| 2379 |
perCallInfo->callSignaling.m.recvAddressPresent = TRUE; |
| 2380 |
perCallInfo->callSignaling.recvAddress.t = T_H225TransportAddress_ipAddress; |
| 2381 |
|
| 2382 |
if (!strcmp(call->callType, "incoming")) { |
| 2383 |
|
| 2384 |
perCallInfo->callSignaling.sendAddress.u.ipAddress = pRemoteAddr; |
| 2385 |
perCallInfo->callSignaling.recvAddress.u.ipAddress = pLocalAddr; |
| 2386 |
} else { |
| 2387 |
|
| 2388 |
perCallInfo->callSignaling.sendAddress.u.ipAddress = pLocalAddr; |
| 2389 |
perCallInfo->callSignaling.recvAddress.u.ipAddress = pRemoteAddr; |
| 2390 |
} |
| 2391 |
|
| 2392 |
|
| 2393 |
perCallInfo->callReferenceValue = call->callReference; |
| 2394 |
|
| 2395 |
memcpy((void*)&perCallInfo->conferenceID, (void*)&call->confIdentifier, |
| 2396 |
sizeof(H225ConferenceIdentifier)); |
| 2397 |
|
| 2398 |
perCallInfo->m.callIdentifierPresent = TRUE; |
| 2399 |
memcpy((void*)&perCallInfo->callIdentifier, (void*)&call->callIdentifier, |
| 2400 |
sizeof(H225CallIdentifier)); |
| 2401 |
|
| 2402 |
perCallInfo->callType.t = T_H225CallType_pointToPoint; |
| 2403 |
|
| 2404 |
if(OO_TESTFLAG(call->flags, OO_M_GKROUTED)) |
| 2405 |
perCallInfo->callModel.t = T_H225CallModel_gatekeeperRouted; |
| 2406 |
else |
| 2407 |
perCallInfo->callModel.t = T_H225CallModel_direct; |
| 2408 |
|
| 2409 |
|
| 2410 |
if (call->alertingTime) { |
| 2411 |
perCallInfo->usageInformation.m.alertingTimePresent = TRUE; |
| 2412 |
perCallInfo->usageInformation.alertingTime = call->alertingTime; |
| 2413 |
} |
| 2414 |
if (call->connectTime) { |
| 2415 |
perCallInfo->usageInformation.m.connectTimePresent = TRUE; |
| 2416 |
perCallInfo->usageInformation.connectTime = call->connectTime; |
| 2417 |
} |
| 2418 |
perCallInfo->usageInformation.m.endTimePresent = FALSE; |
| 2419 |
perCallInfo->m.usageInformationPresent = TRUE; |
| 2420 |
|
| 2421 |
dListInit(&pIRR->perCallInfo); |
| 2422 |
dListAppend(pctxt, &pIRR->perCallInfo, |
| 2423 |
(void*)perCallInfo); |
| 2424 |
|
| 2425 |
iRet = ooGkClientSendMsg(pGkClient, pRasMsg); |
| 2426 |
if(iRet != OO_OK) |
| 2427 |
{ |
| 2428 |
OOTRACEERR1("Error:Failed to send IRR message\n"); |
| 2429 |
memReset(pctxt); |
| 2430 |
pGkClient->state = GkClientGkErr; |
| 2431 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2432 |
return OO_FAILED; |
| 2433 |
} |
| 2434 |
OOTRACEINFO3("IRR message sent for (%s, %s)\n", |
| 2435 |
call->callType, call->callToken); |
| 2436 |
memReset(pctxt); |
| 2437 |
|
| 2438 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2439 |
return OO_OK; |
| 2440 |
} |
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
int ooGkClientSendDisengageRequest(ooGkClient *pGkClient, OOH323CallData *call) |
| 2451 |
{ |
| 2452 |
int iRet = 0; |
| 2453 |
unsigned int x; |
| 2454 |
H225RasMessage *pRasMsg=NULL; |
| 2455 |
OOCTXT *pctxt = NULL; |
| 2456 |
DListNode *pNode = NULL; |
| 2457 |
H225DisengageRequest * pDRQ = NULL; |
| 2458 |
RasCallAdmissionInfo* pCallAdmInfo=NULL; |
| 2459 |
pctxt = &pGkClient->msgCtxt; |
| 2460 |
|
| 2461 |
ast_mutex_lock(&pGkClient->Lock); |
| 2462 |
|
| 2463 |
OOTRACEINFO3("Sending disengage Request for call. (%s, %s)\n", |
| 2464 |
call->callType, call->callToken); |
| 2465 |
|
| 2466 |
pRasMsg = (H225RasMessage*)memAlloc(pctxt, sizeof(H225RasMessage)); |
| 2467 |
if(!pRasMsg) |
| 2468 |
{ |
| 2469 |
OOTRACEERR1("Error: Memory allocation for DRQ RAS message failed\n"); |
| 2470 |
pGkClient->state = GkClientFailed; |
| 2471 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2472 |
return OO_FAILED; |
| 2473 |
} |
| 2474 |
|
| 2475 |
pRasMsg->t = T_H225RasMessage_disengageRequest; |
| 2476 |
pDRQ = (H225DisengageRequest*) memAlloc(pctxt, |
| 2477 |
sizeof(H225DisengageRequest)); |
| 2478 |
if(!pDRQ) |
| 2479 |
{ |
| 2480 |
OOTRACEERR1("Error: Failed to allocate memory for DRQ message\n"); |
| 2481 |
memReset(pctxt); |
| 2482 |
pGkClient->state = GkClientFailed; |
| 2483 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2484 |
return OO_FAILED; |
| 2485 |
} |
| 2486 |
|
| 2487 |
memset(pDRQ, 0, sizeof(H225DisengageRequest)); |
| 2488 |
pRasMsg->u.disengageRequest = pDRQ; |
| 2489 |
|
| 2490 |
pDRQ->requestSeqNum = pGkClient->requestSeqNum++; |
| 2491 |
if(!pDRQ->requestSeqNum ) |
| 2492 |
pDRQ->requestSeqNum = pGkClient->requestSeqNum++; |
| 2493 |
|
| 2494 |
|
| 2495 |
pDRQ->endpointIdentifier.nchars = pGkClient->endpointId.nchars; |
| 2496 |
pDRQ->endpointIdentifier.data = (ASN116BITCHAR*)memAlloc(pctxt, |
| 2497 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 2498 |
if(!pDRQ->endpointIdentifier.data) |
| 2499 |
{ |
| 2500 |
OOTRACEERR1("Error: Failed to allocate memory for EndPoint Id in DRQ " |
| 2501 |
"message.\n"); |
| 2502 |
memReset(pctxt); |
| 2503 |
pGkClient->state = GkClientFailed; |
| 2504 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2505 |
return OO_FAILED; |
| 2506 |
} |
| 2507 |
memcpy((void*)pDRQ->endpointIdentifier.data, |
| 2508 |
(void*)pGkClient->endpointId.data, |
| 2509 |
sizeof(ASN116BITCHAR)*pGkClient->endpointId.nchars); |
| 2510 |
|
| 2511 |
memcpy((void*)&pDRQ->conferenceID, (void*)&call->confIdentifier, |
| 2512 |
sizeof(H225ConferenceIdentifier)); |
| 2513 |
|
| 2514 |
pDRQ->callReferenceValue = call->callReference; |
| 2515 |
|
| 2516 |
pDRQ->disengageReason.t = T_H225DisengageReason_normalDrop; |
| 2517 |
|
| 2518 |
pDRQ->m.answeredCallPresent = 1; |
| 2519 |
if(!strcmp(call->callType, "incoming")) |
| 2520 |
pDRQ->answeredCall = 1; |
| 2521 |
else |
| 2522 |
pDRQ->answeredCall = 0; |
| 2523 |
|
| 2524 |
pDRQ->m.callIdentifierPresent = 1; |
| 2525 |
memcpy((void*)&pDRQ->callIdentifier, (void*)&call->callIdentifier, |
| 2526 |
sizeof(H225CallIdentifier)); |
| 2527 |
if (pGkClient->gkId.nchars) { |
| 2528 |
pDRQ->m.gatekeeperIdentifierPresent = 1; |
| 2529 |
pDRQ->gatekeeperIdentifier.nchars = pGkClient->gkId.nchars; |
| 2530 |
pDRQ->gatekeeperIdentifier.data = (ASN116BITCHAR*)memAlloc |
| 2531 |
(pctxt, pGkClient->gkId.nchars*sizeof(ASN116BITCHAR)); |
| 2532 |
if(!pDRQ->gatekeeperIdentifier.data) |
| 2533 |
{ |
| 2534 |
OOTRACEERR1("Error:Failed to allocate memory for GKId in DRQ.\n"); |
| 2535 |
memReset(pctxt); |
| 2536 |
pGkClient->state = GkClientFailed; |
| 2537 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2538 |
return OO_FAILED; |
| 2539 |
} |
| 2540 |
memcpy(pDRQ->gatekeeperIdentifier.data, pGkClient->gkId.data, |
| 2541 |
pGkClient->gkId.nchars*sizeof(ASN116BITCHAR)); |
| 2542 |
} |
| 2543 |
|
| 2544 |
pDRQ->m.terminationCausePresent = 1; |
| 2545 |
pDRQ->terminationCause.t = T_H225CallTerminationCause_releaseCompleteCauseIE; |
| 2546 |
pDRQ->terminationCause.u.releaseCompleteCauseIE = |
| 2547 |
(H225CallTerminationCause_releaseCompleteCauseIE*)memAlloc(pctxt, |
| 2548 |
sizeof(H225CallTerminationCause_releaseCompleteCauseIE)); |
| 2549 |
if(!pDRQ->terminationCause.u.releaseCompleteCauseIE) |
| 2550 |
{ |
| 2551 |
OOTRACEERR1("Error: Failed to allocate memory for cause ie in DRQ.\n"); |
| 2552 |
memReset(pctxt); |
| 2553 |
pGkClient->state = GkClientFailed; |
| 2554 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2555 |
return OO_FAILED; |
| 2556 |
} |
| 2557 |
pDRQ->terminationCause.u.releaseCompleteCauseIE->numocts = |
| 2558 |
strlen("Call Ended"); |
| 2559 |
strcpy((char *)pDRQ->terminationCause.u.releaseCompleteCauseIE->data, "Call Ended"); |
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
if (call->alertingTime) { |
| 2565 |
pDRQ->usageInformation.m.alertingTimePresent = TRUE; |
| 2566 |
pDRQ->usageInformation.alertingTime = call->alertingTime; |
| 2567 |
} |
| 2568 |
if (call->connectTime) { |
| 2569 |
pDRQ->usageInformation.m.connectTimePresent = TRUE; |
| 2570 |
pDRQ->usageInformation.connectTime = call->connectTime; |
| 2571 |
} |
| 2572 |
pDRQ->usageInformation.m.endTimePresent = TRUE; |
| 2573 |
if (call->endTime) |
| 2574 |
pDRQ->usageInformation.endTime = call->endTime; |
| 2575 |
else |
| 2576 |
pDRQ->usageInformation.endTime = time(NULL); |
| 2577 |
pDRQ->m.usageInformationPresent = TRUE; |
| 2578 |
|
| 2579 |
iRet = ooGkClientSendMsg(pGkClient, pRasMsg); |
| 2580 |
if(iRet != OO_OK) |
| 2581 |
{ |
| 2582 |
OOTRACEERR1("Error: Failed to send DRQ message\n"); |
| 2583 |
pGkClient->state = GkClientGkErr; |
| 2584 |
} |
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
for(x=0 ; x<pGkClient->callsAdmittedList.count ; x++) |
| 2590 |
{ |
| 2591 |
pNode = (DListNode*)dListFindByIndex(&pGkClient->callsAdmittedList, x); |
| 2592 |
pCallAdmInfo = (RasCallAdmissionInfo*) pNode->data; |
| 2593 |
if(pCallAdmInfo->call->callReference == call->callReference) |
| 2594 |
{ |
| 2595 |
dListRemove( &pGkClient->callsAdmittedList, pNode); |
| 2596 |
memFreePtr(&pGkClient->ctxt, pNode->data); |
| 2597 |
memFreePtr(&pGkClient->ctxt, pNode); |
| 2598 |
break; |
| 2599 |
} |
| 2600 |
} |
| 2601 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2602 |
return iRet; |
| 2603 |
} |
| 2604 |
|
| 2605 |
int ooGkClientHandleDisengageConfirm |
| 2606 |
(ooGkClient *pGkClient, H225DisengageConfirm *pDCF) |
| 2607 |
{ |
| 2608 |
OOTRACEINFO1("Received disengage confirm\n"); |
| 2609 |
return OO_OK; |
| 2610 |
} |
| 2611 |
|
| 2612 |
int ooGkClientRRQTimerExpired(void*pdata) |
| 2613 |
{ |
| 2614 |
int ret=0; |
| 2615 |
ooGkClientTimerCb *cbData = (ooGkClientTimerCb*)pdata; |
| 2616 |
ooGkClient *pGkClient = cbData->pGkClient; |
| 2617 |
OOTRACEDBGA1("Gatekeeper client RRQ timer expired.\n"); |
| 2618 |
|
| 2619 |
if(pGkClient->rrqRetries < OO_MAX_RRQ_RETRIES) |
| 2620 |
{ |
| 2621 |
ret = ooGkClientSendRRQ(pGkClient, 0); |
| 2622 |
if(ret != OO_OK) |
| 2623 |
{ |
| 2624 |
OOTRACEERR1("Error:Failed to send RRQ message\n"); |
| 2625 |
|
| 2626 |
return OO_FAILED; |
| 2627 |
} |
| 2628 |
pGkClient->rrqRetries++; |
| 2629 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 2630 |
return OO_OK; |
| 2631 |
} |
| 2632 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 2633 |
OOTRACEERR1("Error:Failed to register with gatekeeper\n"); |
| 2634 |
pGkClient->state = GkClientUnregistered; |
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
ast_mutex_lock(&pGkClient->Lock); |
| 2641 |
|
| 2642 |
cbData = (ooGkClientTimerCb*) memAlloc |
| 2643 |
(&pGkClient->ctxt, sizeof(ooGkClientTimerCb)); |
| 2644 |
if(!cbData) |
| 2645 |
{ |
| 2646 |
OOTRACEERR1("Error:Failed to allocate memory to RRQ timer callback\n"); |
| 2647 |
pGkClient->state = GkClientFailed; |
| 2648 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2649 |
return OO_FAILED; |
| 2650 |
} |
| 2651 |
|
| 2652 |
|
| 2653 |
cbData->timerType = OO_RRQ_TIMER; |
| 2654 |
cbData->pGkClient = pGkClient; |
| 2655 |
if(!ooTimerCreate(&pGkClient->ctxt, &pGkClient->timerList, |
| 2656 |
&ooGkClientRRQTimerExpired, pGkClient->regTimeout, |
| 2657 |
cbData, FALSE)) |
| 2658 |
{ |
| 2659 |
OOTRACEERR1("Error:Unable to create GRQ timer.\n "); |
| 2660 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 2661 |
pGkClient->state = GkClientFailed; |
| 2662 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2663 |
return OO_FAILED; |
| 2664 |
} |
| 2665 |
|
| 2666 |
|
| 2667 |
pGkClient->rrqRetries = 0; |
| 2668 |
|
| 2669 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2670 |
|
| 2671 |
return OO_FAILED; |
| 2672 |
} |
| 2673 |
|
| 2674 |
int ooGkClientGRQTimerExpired(void* pdata) |
| 2675 |
{ |
| 2676 |
int ret=0; |
| 2677 |
ooGkClientTimerCb *cbData = (ooGkClientTimerCb*)pdata; |
| 2678 |
ooGkClient *pGkClient = cbData->pGkClient; |
| 2679 |
|
| 2680 |
OOTRACEDBGA1("Gatekeeper client GRQ timer expired.\n"); |
| 2681 |
|
| 2682 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 2683 |
|
| 2684 |
if(pGkClient->grqRetries < OO_MAX_GRQ_RETRIES) |
| 2685 |
{ |
| 2686 |
ret = ooGkClientSendGRQ(pGkClient); |
| 2687 |
if(ret != OO_OK) |
| 2688 |
{ |
| 2689 |
OOTRACEERR1("Error:Failed to send GRQ message\n"); |
| 2690 |
pGkClient->state = GkClientFailed; |
| 2691 |
return OO_FAILED; |
| 2692 |
} |
| 2693 |
pGkClient->grqRetries++; |
| 2694 |
return OO_OK; |
| 2695 |
} |
| 2696 |
|
| 2697 |
OOTRACEERR1("Error:Gatekeeper could not be found\n"); |
| 2698 |
pGkClient->state = GkClientUnregistered; |
| 2699 |
|
| 2700 |
|
| 2701 |
ast_mutex_lock(&pGkClient->Lock); |
| 2702 |
cbData = (ooGkClientTimerCb*) memAlloc |
| 2703 |
(&pGkClient->ctxt, sizeof(ooGkClientTimerCb)); |
| 2704 |
if(!cbData) |
| 2705 |
{ |
| 2706 |
OOTRACEERR1("Error:Failed to allocate memory to GRQ timer callback\n"); |
| 2707 |
pGkClient->state = GkClientFailed; |
| 2708 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2709 |
return OO_FAILED; |
| 2710 |
} |
| 2711 |
cbData->timerType = OO_GRQ_TIMER; |
| 2712 |
cbData->pGkClient = pGkClient; |
| 2713 |
if(!ooTimerCreate(&pGkClient->ctxt, &pGkClient->timerList, |
| 2714 |
&ooGkClientGRQTimerExpired, pGkClient->grqTimeout, |
| 2715 |
cbData, FALSE)) |
| 2716 |
{ |
| 2717 |
OOTRACEERR1("Error:Unable to create GRQ timer.\n "); |
| 2718 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 2719 |
pGkClient->state = GkClientFailed; |
| 2720 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2721 |
return OO_FAILED; |
| 2722 |
} |
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
pGkClient->grqRetries = 0; |
| 2727 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2728 |
|
| 2729 |
return OO_FAILED; |
| 2730 |
} |
| 2731 |
|
| 2732 |
int ooGkClientREGTimerExpired(void *pdata) |
| 2733 |
{ |
| 2734 |
int ret=0; |
| 2735 |
ooGkClientTimerCb *cbData = (ooGkClientTimerCb*)pdata; |
| 2736 |
ooGkClient *pGkClient = cbData->pGkClient; |
| 2737 |
OOTRACEDBGA1("Gatekeeper client additive registration timer expired\n"); |
| 2738 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 2739 |
ret = ooGkClientSendRRQ(pGkClient, TRUE); |
| 2740 |
if(ret != OO_OK) |
| 2741 |
{ |
| 2742 |
OOTRACEERR1("Error:Failed to send Additive RRQ message\n"); |
| 2743 |
pGkClient->state = GkClientGkErr; |
| 2744 |
return OO_FAILED; |
| 2745 |
} |
| 2746 |
return OO_OK; |
| 2747 |
} |
| 2748 |
|
| 2749 |
int ooGkClientARQTimerExpired(void* pdata) |
| 2750 |
{ |
| 2751 |
int ret=0; |
| 2752 |
ooGkClientTimerCb *cbData = (ooGkClientTimerCb*)pdata; |
| 2753 |
ooGkClient *pGkClient = cbData->pGkClient; |
| 2754 |
RasCallAdmissionInfo *pAdmInfo = cbData->pAdmInfo; |
| 2755 |
|
| 2756 |
OOTRACEDBGA1("Gatekeeper client ARQ timer expired.\n"); |
| 2757 |
memFreePtr(&pGkClient->ctxt, cbData); |
| 2758 |
|
| 2759 |
if(!pAdmInfo) |
| 2760 |
return OO_OK; |
| 2761 |
|
| 2762 |
if(pAdmInfo->retries < OO_MAX_ARQ_RETRIES) |
| 2763 |
{ |
| 2764 |
ret = ooGkClientSendAdmissionRequest(pGkClient, pAdmInfo->call, TRUE); |
| 2765 |
if(ret != OO_OK) |
| 2766 |
{ |
| 2767 |
OOTRACEERR1("Error:Failed to send ARQ message\n"); |
| 2768 |
return OO_FAILED; |
| 2769 |
} |
| 2770 |
pAdmInfo->retries++; |
| 2771 |
return OO_OK; |
| 2772 |
} |
| 2773 |
|
| 2774 |
OOTRACEERR1("Error:Gatekeeper not responding to ARQ\n"); |
| 2775 |
pGkClient->state = GkClientGkErr; |
| 2776 |
return OO_FAILED; |
| 2777 |
} |
| 2778 |
|
| 2779 |
int ooGkClientCleanCall(ooGkClient *pGkClient, OOH323CallData *call) |
| 2780 |
{ |
| 2781 |
unsigned int x=0; |
| 2782 |
DListNode *pNode=NULL; |
| 2783 |
OOTimer *pTimer; |
| 2784 |
ooGkClientTimerCb *cbData=NULL; |
| 2785 |
RasCallAdmissionInfo *pAdmInfo = NULL; |
| 2786 |
|
| 2787 |
ast_mutex_lock(&pGkClient->Lock); |
| 2788 |
|
| 2789 |
|
| 2790 |
for(x=0; x<pGkClient->callsAdmittedList.count; x++) |
| 2791 |
{ |
| 2792 |
pNode = dListFindByIndex(&pGkClient->callsAdmittedList, x); |
| 2793 |
pAdmInfo = (RasCallAdmissionInfo*)pNode->data; |
| 2794 |
if(pAdmInfo->call->callReference == call->callReference) |
| 2795 |
{ |
| 2796 |
dListRemove(&pGkClient->callsAdmittedList, pNode); |
| 2797 |
memFreePtr(&pGkClient->ctxt, pAdmInfo); |
| 2798 |
memFreePtr(&pGkClient->ctxt, pNode); |
| 2799 |
break; |
| 2800 |
} |
| 2801 |
} |
| 2802 |
|
| 2803 |
|
| 2804 |
for(x=0; x<pGkClient->timerList.count; x++) |
| 2805 |
{ |
| 2806 |
pNode = dListFindByIndex(&pGkClient->timerList, x); |
| 2807 |
pTimer = (OOTimer*)pNode->data; |
| 2808 |
cbData = (ooGkClientTimerCb*)pTimer->cbData; |
| 2809 |
if(cbData->timerType & OO_ARQ_TIMER && |
| 2810 |
cbData->pAdmInfo->call->callReference == call->callReference) |
| 2811 |
{ |
| 2812 |
memFreePtr(&pGkClient->ctxt, pTimer->cbData); |
| 2813 |
ooTimerDelete(&pGkClient->ctxt, &pGkClient->timerList, pTimer); |
| 2814 |
break; |
| 2815 |
} |
| 2816 |
} |
| 2817 |
|
| 2818 |
for(x=0; x<pGkClient->callsPendingList.count; x++) |
| 2819 |
{ |
| 2820 |
pNode = dListFindByIndex(&pGkClient->callsPendingList, x); |
| 2821 |
pAdmInfo = (RasCallAdmissionInfo*)pNode->data; |
| 2822 |
if(pAdmInfo->call->callReference == call->callReference) |
| 2823 |
{ |
| 2824 |
dListRemove(&pGkClient->callsPendingList, pNode); |
| 2825 |
memFreePtr(&pGkClient->ctxt, pAdmInfo); |
| 2826 |
memFreePtr(&pGkClient->ctxt, pNode); |
| 2827 |
break; |
| 2828 |
} |
| 2829 |
} |
| 2830 |
|
| 2831 |
ast_mutex_unlock(&pGkClient->Lock); |
| 2832 |
return OO_OK; |
| 2833 |
} |
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
int ooGkClientHandleClientOrGkFailure(ooGkClient *pGkClient) |
| 2843 |
{ |
| 2844 |
if(pGkClient->state == GkClientFailed) |
| 2845 |
{ |
| 2846 |
OOTRACEERR1("Error: Internal Failure in GkClient. Closing " |
| 2847 |
"GkClient\n"); |
| 2848 |
ooGkClientDestroy(); |
| 2849 |
return OO_FAILED; |
| 2850 |
} |
| 2851 |
else if(pGkClient->state == GkClientGkErr) { |
| 2852 |
OOTRACEERR1("Error: Gatekeeper error. Either Gk not responding or " |
| 2853 |
"Gk sending invalid messages\n"); |
| 2854 |
if(pGkClient->gkMode == RasUseSpecificGatekeeper) |
| 2855 |
{ |
| 2856 |
OOTRACEERR1("Error: Gatekeeper error detected. Closing GkClient as " |
| 2857 |
"Gk mode is UseSpecifcGatekeeper\n"); |
| 2858 |
pGkClient->state = GkClientStopped; |
| 2859 |
return OO_FAILED; |
| 2860 |
} |
| 2861 |
else{ |
| 2862 |
OOTRACEERR1("Error: Gatekeeper error detected. Closing GkClient. NEED" |
| 2863 |
" to implement recovery by rediscovering another gk\n"); |
| 2864 |
pGkClient->state = GkClientStopped; |
| 2865 |
return OO_FAILED; |
| 2866 |
} |
| 2867 |
} |
| 2868 |
|
| 2869 |
return OO_FAILED; |
| 2870 |
} |
| 2871 |
|
| 2872 |
|
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
int ooGkClientUpdateRegisteredAliases |
| 2882 |
(ooGkClient *pGkClient, H225_SeqOfH225AliasAddress *pAddresses, |
| 2883 |
OOBOOL registered) |
| 2884 |
{ |
| 2885 |
int i=0, j, k; |
| 2886 |
DListNode* pNode=NULL; |
| 2887 |
ooAliases *pAlias=NULL; |
| 2888 |
H225AliasAddress *pAliasAddress=NULL; |
| 2889 |
H225TransportAddress *pTransportAddrss=NULL; |
| 2890 |
char value[MAXFILENAME]; |
| 2891 |
OOBOOL bAdd = FALSE; |
| 2892 |
|
| 2893 |
if(!pAddresses) |
| 2894 |
{ |
| 2895 |
|
| 2896 |
pAlias = gH323ep.aliases; |
| 2897 |
|
| 2898 |
while(pAlias) |
| 2899 |
{ |
| 2900 |
pAlias->registered = registered?TRUE:FALSE; |
| 2901 |
pAlias = pAlias->next; |
| 2902 |
} |
| 2903 |
return OO_OK; |
| 2904 |
} |
| 2905 |
|
| 2906 |
|
| 2907 |
if(pAddresses->count<=0) |
| 2908 |
return OO_FAILED; |
| 2909 |
|
| 2910 |
for(i=0; i<(int)pAddresses->count; i++) |
| 2911 |
{ |
| 2912 |
pNode = dListFindByIndex (pAddresses, i); |
| 2913 |
if(!pNode) |
| 2914 |
{ |
| 2915 |
OOTRACEERR1("Error:Invalid alias list passed to " |
| 2916 |
"ooGkClientUpdateRegisteredAliases\n"); |
| 2917 |
continue; |
| 2918 |
} |
| 2919 |
pAliasAddress = (H225AliasAddress*)pNode->data; |
| 2920 |
|
| 2921 |
if(!pAliasAddress){ |
| 2922 |
OOTRACEERR1("Error:Invalid alias list passed to " |
| 2923 |
"ooGkClientUpdateRegisteredAliases\n"); |
| 2924 |
continue; |
| 2925 |
} |
| 2926 |
|
| 2927 |
switch(pAliasAddress->t) |
| 2928 |
{ |
| 2929 |
case T_H225AliasAddress_dialedDigits: |
| 2930 |
pAlias = ooH323GetAliasFromList(gH323ep.aliases, |
| 2931 |
T_H225AliasAddress_dialedDigits, |
| 2932 |
(char*)pAliasAddress->u.dialedDigits); |
| 2933 |
if(pAlias) |
| 2934 |
{ |
| 2935 |
pAlias->registered = registered?TRUE:FALSE; |
| 2936 |
} |
| 2937 |
else{ |
| 2938 |
bAdd = registered?TRUE:FALSE; |
| 2939 |
} |
| 2940 |
break; |
| 2941 |
case T_H225AliasAddress_h323_ID: |
| 2942 |
for(j=0, k=0; j<(int)pAliasAddress->u.h323_ID.nchars && (k<MAXFILENAME-1); j++) |
| 2943 |
{ |
| 2944 |
if(pAliasAddress->u.h323_ID.data[j] < 256) |
| 2945 |
{ |
| 2946 |
value[k++] = (char) pAliasAddress->u.h323_ID.data[j]; |
| 2947 |
} |
| 2948 |
} |
| 2949 |
value[k] = '\0'; |
| 2950 |
pAlias = ooH323GetAliasFromList(gH323ep.aliases, |
| 2951 |
T_H225AliasAddress_h323_ID, |
| 2952 |
value); |
| 2953 |
if(pAlias) |
| 2954 |
{ |
| 2955 |
pAlias->registered = registered?TRUE:FALSE; |
| 2956 |
} |
| 2957 |
else{ |
| 2958 |
bAdd = registered?TRUE:FALSE; |
| 2959 |
} |
| 2960 |
break; |
| 2961 |
case T_H225AliasAddress_url_ID: |
| 2962 |
pAlias = ooH323GetAliasFromList(gH323ep.aliases, |
| 2963 |
T_H225AliasAddress_url_ID, |
| 2964 |
(char*)pAliasAddress->u.url_ID); |
| 2965 |
if(pAlias) |
| 2966 |
{ |
| 2967 |
pAlias->registered = registered?TRUE:FALSE; |
| 2968 |
} |
| 2969 |
else{ |
| 2970 |
bAdd = registered?TRUE:FALSE; |
| 2971 |
} |
| 2972 |
break; |
| 2973 |
case T_H225AliasAddress_transportID: |
| 2974 |
pTransportAddrss = pAliasAddress->u.transportID; |
| 2975 |
if(pTransportAddrss->t != T_H225TransportAddress_ipAddress) |
| 2976 |
{ |
| 2977 |
OOTRACEERR1("Error:Alias transportID not IP address\n"); |
| 2978 |
break; |
| 2979 |
} |
| 2980 |
|
| 2981 |
sprintf(value, "%d.%d.%d.%d:%d", |
| 2982 |
pTransportAddrss->u.ipAddress->ip.data[0], |
| 2983 |
pTransportAddrss->u.ipAddress->ip.data[1], |
| 2984 |
pTransportAddrss->u.ipAddress->ip.data[2], |
| 2985 |
pTransportAddrss->u.ipAddress->ip.data[3], |
| 2986 |
pTransportAddrss->u.ipAddress->port); |
| 2987 |
|
| 2988 |
pAlias = ooH323GetAliasFromList(gH323ep.aliases, |
| 2989 |
T_H225AliasAddress_transportID, |
| 2990 |
value); |
| 2991 |
if(pAlias) |
| 2992 |
{ |
| 2993 |
pAlias->registered = registered?TRUE:FALSE; |
| 2994 |
} |
| 2995 |
else{ |
| 2996 |
bAdd = registered?TRUE:FALSE; |
| 2997 |
} |
| 2998 |
break; |
| 2999 |
case T_H225AliasAddress_email_ID: |
| 3000 |
pAlias = ooH323GetAliasFromList(gH323ep.aliases, |
| 3001 |
T_H225AliasAddress_email_ID, |
| 3002 |
(char*) pAliasAddress->u.email_ID); |
| 3003 |
if(pAlias) |
| 3004 |
{ |
| 3005 |
pAlias->registered = registered?TRUE:FALSE; |
| 3006 |
} |
| 3007 |
else{ |
| 3008 |
bAdd = registered?TRUE:FALSE; |
| 3009 |
} |
| 3010 |
break; |
| 3011 |
default: |
| 3012 |
OOTRACEERR1("Error:Unhandled alias type found in registered " |
| 3013 |
"aliases\n"); |
| 3014 |
} |
| 3015 |
if(bAdd) |
| 3016 |
{ |
| 3017 |
pAlias = ooH323AddAliasToList(&gH323ep.aliases, |
| 3018 |
&gH323ep.ctxt, pAliasAddress); |
| 3019 |
if(pAlias){ |
| 3020 |
pAlias->registered = registered?TRUE:FALSE; |
| 3021 |
} |
| 3022 |
else{ |
| 3023 |
OOTRACEERR2("Warning:Could not add registered alias of " |
| 3024 |
"type %d to list.\n", pAliasAddress->t); |
| 3025 |
} |
| 3026 |
bAdd = FALSE; |
| 3027 |
} |
| 3028 |
pAlias = NULL; |
| 3029 |
} |
| 3030 |
return OO_OK; |
| 3031 |
} |