1 /* 2 ** $Id: owampP.h 1038 2009-01-07 17:33:42Z aaron $ 3 */ 4 /************************************************************************ 5 * * 6 * Copyright (C) 2002 * 7 * Internet2 * 8 * All Rights Reserved * 9 * * 10 ************************************************************************/ 11 /* 12 ** File: owampP.h 13 ** 14 ** Author: Jeff W. Boote 15 ** Anatoly Karp 16 ** 17 ** Date: Wed Mar 20 11:10:33 2002 18 ** 19 ** Description: 20 ** This header file describes the internal-private owamp API. 21 ** 22 ** testing 23 */ 24 #ifndef OWAMPP_H 25 #define OWAMPP_H 26 27 #include <owamp/owamp.h> 28 29 #include <I2util/util.h> 30 #include <I2util/hmac-sha1.h> 31 32 #include <stdlib.h> 33 #include <stdio.h> 34 #include <errno.h> 35 #include <string.h> 36 #include <unistd.h> 37 #include <netdb.h> 38 #include <sys/types.h> 39 #include <sys/stat.h> 40 #include <sys/time.h> 41 #include <sys/socket.h> 42 #include <sys/param.h> 43 #include <netinet/in.h> 44 45 #ifndef MAXHOSTNAMELEN 46 #define MAXHOSTNAMELEN 64 47 #endif 48 49 #ifndef EFTYPE 50 #define EFTYPE ENOSYS 51 #endif 52 53 54 /* 55 * Default temporary directory name 56 */ 57 #define _OWP_DEFAULT_TMPDIR "/tmp" 58 #define _OWP_SKIPFILE_FMT "owpskips.XXXXXX" 59 60 /* 61 * Default 'count' for pbkdf2() for key generation 62 */ 63 #define _OWP_DEFAULT_PBKDF2_COUNT (2048) 64 65 /* 66 * Offset's and lengths for various file versions. 67 */ 68 #define _OWP_TESTREC_OFFSET (40) 69 #define _OWP_DATARECV2_SIZE (24) 70 #define _OWP_DATARECV3_SIZE (25) 71 #define _OWP_DATAREC_SIZE _OWP_DATARECV3_SIZE 72 #define _OWP_MAXDATAREC_SIZE _OWP_DATAREC_SIZE 73 #define _OWP_SKIPREC_SIZE (8) 74 75 /* 76 * Size of a single AES block 77 */ 78 #define _OWP_RIJNDAEL_BLOCK_SIZE 16 79 80 /* 81 * Size of token,salt - SetupResponseMessage 82 */ 83 #define _OWP_TOKEN_SIZE (64) 84 #define _OWP_SALT_SIZE (16) 85 86 /* 87 * The FETCH buffer is the smallest multiple of both the _OWP_DATAREC_SIZE 88 * and the _OWP_RIJNDAEL_BLOCK_SIZE. The following must be true: 89 * _OWP_FETCH_AES_BLOCKS * _OWP_RIJNDAEL_BLOCK_SIZE == _OWP_FETCH_BUFFSIZE 90 * _OWP_FETCH_DATAREC_BLOCKS * _OWP_DATAREC_SIZE == _OWP_FETCH_BUFFSIZE 91 */ 92 #define _OWP_FETCHV2_BUFFSIZE 48 93 #define _OWP_FETCHV2_AES_BLOCKS 3 94 #define _OWP_FETCHV2_DATAREC_BLOCKS 2 95 #define _OWP_FETCHV3_BUFFSIZE 400 96 #define _OWP_FETCHV3_AES_BLOCKS 25 97 #define _OWP_FETCHV3_DATAREC_BLOCKS 16 98 #define _OWP_FETCH_BUFFSIZE (_OWP_FETCHV3_BUFFSIZE) 99 #define _OWP_FETCH_AES_BLOCKS (_OWP_FETCHV3_AES_BLOCKS) 100 #define _OWP_FETCH_DATAREC_BLOCKS (_OWP_FETCHV3_DATAREC_BLOCKS) 101 102 #if (_OWP_FETCH_BUFFSIZE != (_OWP_RIJNDAEL_BLOCK_SIZE * _OWP_FETCH_AES_BLOCKS)) 103 #error "Fetch Buffer is mis-sized for AES block size!" 104 #endif 105 #if (_OWP_FETCH_BUFFSIZE != (_OWP_DATAREC_SIZE * _OWP_FETCH_DATAREC_BLOCKS)) 106 #error "Fetch Buffer is mis-sized for Test Record Size!" 107 #endif 108 /* 109 ** Lengths (in 16-byte blocks) of various Control messages. 110 */ 111 #define _OWP_TEST_REQUEST_BLK_LEN 7 112 #define _OWP_START_SESSIONS_BLK_LEN 2 113 #define _OWP_STOP_SESSIONS_BLK_LEN 2 114 #define _OWP_FETCH_SESSION_BLK_LEN 3 115 #define _OWP_START_ACK_BLK_LEN 2 116 #define _OWP_FETCH_ACK_BLK_LEN 2 117 #define _OWP_MAX_MSG_BLK_LEN _OWP_FETCHV3_AES_BLOCKS 118 119 #define _OWP_MAX_MSG_SIZE (_OWP_MAX_MSG_BLK_LEN*_OWP_RIJNDAEL_BLOCK_SIZE) 120 #define _OWP_TEST_REQUEST_PREAMBLE_SIZE (_OWP_TEST_REQUEST_BLK_LEN*_OWP_RIJNDAEL_BLOCK_SIZE) 121 122 /* 123 * Control state constants. 124 * (Used to keep track of partially read messages, and to make debugging 125 * control session state easier to manage.) 126 */ 127 /* initial & invalid */ 128 #define _OWPStateInitial (0x0000) 129 #define _OWPStateInvalid (0x0000) 130 /* during negotiation */ 131 #define _OWPStateSetup (0x0001) 132 #define _OWPStateUptime (_OWPStateSetup << 1) 133 /* after negotiation ready for requests */ 134 #define _OWPStateRequest (_OWPStateUptime << 1) 135 /* test sessions are active */ 136 #define _OWPStateTest (_OWPStateRequest << 1) 137 /* 138 * The following states are for partially read messages on the server. 139 */ 140 #define _OWPStateTestRequest (_OWPStateTest << 1) 141 #define _OWPStateTestRequestSlots (_OWPStateTestRequest << 1) 142 #define _OWPStateStartSessions (_OWPStateTestRequestSlots << 1) 143 #define _OWPStateStopSessions (_OWPStateStartSessions << 1) 144 #define _OWPStateFetchSession (_OWPStateStopSessions << 1) 145 #define _OWPStateAcceptSession (_OWPStateFetchSession << 1) 146 #define _OWPStateStartAck (_OWPStateAcceptSession << 1) 147 /* during fetch-session */ 148 #define _OWPStateFetchAck (_OWPStateStartAck << 1) 149 #define _OWPStateFetching (_OWPStateFetchAck << 1) 150 #define _OWPStateFetchingRecords (_OWPStateFetching << 1) 151 152 /* Reading indicates partial read request-ReadRequestType without remainder */ 153 #define _OWPStateReading (_OWPStateTestRequest|_OWPStateStartSessions|_OWPStateStopSessions|_OWPStateFetchSession) 154 155 /* 156 * "Pending" indicates waiting for server response to a request. 157 */ 158 #define _OWPStatePending (_OWPStateAcceptSession|_OWPStateStartAck|_OWPStateStopSessions|_OWPStateFetchAck) 159 160 161 #define _OWPStateIsInitial(c) (!(c)->state) 162 #define _OWPStateIsSetup(c) (!(_OWPStateSetup ^ (c)->state)) 163 #define _OWPStateIs(teststate,c) ((teststate & (c)->state)) 164 #define _OWPStateIsRequest(c) _OWPStateIs(_OWPStateRequest,c) 165 #define _OWPStateIsReading(c) _OWPStateIs((_OWPStateReading),c) 166 #define _OWPStateIsPending(c) _OWPStateIs(_OWPStatePending,c) 167 #define _OWPStateIsFetchSession(c) _OWPStateIs(_OWPStateFetchSession,c) 168 #define _OWPStateIsFetching(c) _OWPStateIs(_OWPStateFetching,c) 169 #define _OWPStateIsTest(c) _OWPStateIs(_OWPStateTest,c) 170 171 /* 172 * other useful constants. 173 */ 174 #define _OWP_ERR_MAXSTRING (1024) 175 #define _OWP_MAGIC_FILETYPE "OwA" 176 #define _OWP_DEFAULT_FUZZTIME (1.0) 177 178 /* 179 * Data structures 180 */ 181 typedef struct OWPContextRec OWPContextRec; 182 typedef struct OWPControlRec OWPControlRec; 183 184 #define _OWP_CONTEXT_TABLE_SIZE 64 185 #define _OWP_CONTEXT_MAX_KEYLEN 64 186 187 struct OWPContextRec{ 188 OWPBoolean lib_eh; 189 I2ErrHandle eh; 190 I2Table table; 191 I2RandomSource rand_src; 192 uint32_t pbkdf2_count; 193 OWPControlRec *cntrl_list; 194 }; 195 196 typedef struct OWPTestSessionRec OWPTestSessionRec, *OWPTestSession; 197 struct OWPControlRec{ 198 /* 199 * Application configuration information. 200 */ 201 OWPContext ctx; 202 203 /* 204 * Hash for maintaining Policy state data. 205 */ 206 I2Table table; 207 208 /* 209 * Control connection state information. 210 */ 211 OWPBoolean server; /* this record represents server */ 212 int state; /* current state of connection */ 213 OWPSessionMode mode; 214 215 /* 216 * Very rough upper bound estimate of rtt. 217 * Used by clients to estimate a good "start" time for tests that 218 * is just beyond the amount of time it takes to request the test. 219 */ 220 OWPNum64 rtt_bound; 221 222 /* 223 * This field is initialized to zero and used for comparisons 224 * to ensure AES is working. 225 */ 226 char zero[16]; 227 228 /* 229 * area for peer's messages, make uint32_t to get integer alignment. 230 * Cast to char * when used... C99 indicates (char *) as only valid 231 * type for punning like this. 232 */ 233 uint32_t msg[_OWP_MAX_MSG_SIZE/sizeof(uint32_t)]; 234 235 /* 236 * Address specification and "network" information. 237 * (Control socket addr information) 238 */ 239 I2Addr remote_addr; 240 I2Addr local_addr; 241 int sockfd; 242 243 /* 244 * Encryption fields 245 */ 246 /* null if not set - else userid_buffer */ 247 char *userid; 248 OWPUserID userid_buffer; 249 keyInstance encrypt_key; 250 keyInstance decrypt_key; 251 uint8_t aessession_key[16]; 252 uint8_t readIV[16]; 253 uint8_t writeIV[16]; 254 255 uint8_t hmac_key[32]; 256 I2HMACSha1Context send_hmac_ctx; 257 I2HMACSha1Context recv_hmac_ctx; 258 259 int *retn_on_intr; 260 261 struct OWPControlRec *next; 262 OWPTestSession tests; 263 }; 264 265 typedef struct OWPLostPacketRec OWPLostPacketRec, *OWPLostPacket; 266 struct OWPLostPacketRec{ 267 uint32_t seq; 268 OWPBoolean hit; 269 OWPNum64 relative; 270 struct timespec absolute; /* absolute time */ 271 OWPLostPacket next; 272 }; 273 274 typedef struct _OWPSkipRec _OWPSkipRec, *_OWPSkip; 275 struct _OWPSkipRec{ 276 OWPSkipRec sr; 277 _OWPSkip next; 278 }; 279 280 /* 281 * This type holds all the information needed for an endpoint to be 282 * managed. 283 */ 284 typedef struct OWPEndpointRec{ 285 OWPControl cntrl; 286 OWPTestSession tsession; 287 288 #ifndef NDEBUG 289 I2Boolean childwait; 290 #endif 291 292 OWPAcceptType acceptval; 293 pid_t child; 294 int wopts; 295 OWPBoolean send; 296 int sockfd; 297 int skiprecfd; 298 off_t skiprecsize; 299 I2Addr remoteaddr; 300 I2Addr localaddr; 301 302 /* 303 * crypt fields 304 */ 305 uint8_t aesbytes[_OWP_RIJNDAEL_BLOCK_SIZE]; 306 keyInstance aeskey; 307 uint8_t hmac_key[32]; 308 I2HMACSha1Context hmac_ctx; 309 310 char fname[PATH_MAX]; 311 FILE *userfile; /* from _OWPOpenFile */ 312 FILE *datafile; /* correct buffering */ 313 char *fbuff; 314 315 struct timespec start; 316 struct timespec enddelay; 317 char *payload; 318 319 size_t len_payload; 320 321 322 /* Keep track of "lost" packets */ 323 uint32_t numalist; 324 OWPLostPacket lost_allocated; 325 OWPLostPacket freelist; 326 OWPLostPacket begin; 327 OWPLostPacket end; 328 I2Table lost_packet_buffer; 329 330 /* Keep track of which packets the sender actually sent */ 331 uint32_t nextseq; 332 uint32_t num_allocskip; 333 _OWPSkip skip_allocated; 334 _OWPSkip free_skiplist; 335 _OWPSkip head_skip; 336 _OWPSkip tail_skip; 337 338 } OWPEndpointRec, *OWPEndpoint; 339 340 #define _OWPSLOT_BUFSIZE 10 341 struct OWPTestSessionRec{ 342 OWPControl cntrl; 343 OWPSID sid; 344 I2Addr sender; 345 I2Addr receiver; 346 OWPBoolean conf_sender; 347 OWPBoolean conf_receiver; 348 OWPTestSpec test_spec; 349 OWPSlot slot_buffer[_OWPSLOT_BUFSIZE]; 350 351 OWPEndpoint endpoint; 352 void *closure; /* per/test app data */ 353 354 /* schedule */ 355 OWPScheduleContext sctx; 356 357 /* For send sessions, what packets were actually sent */ 358 uint32_t nextseq; 359 uint32_t nskips; 360 OWPSkipRec skips; 361 362 OWPTestSession next; 363 }; 364 365 /* 366 * Private api.c prototypes 367 */ 368 369 extern OWPTestSession 370 _OWPTestSessionAlloc( 371 OWPControl cntrl, 372 I2Addr sender, 373 OWPBoolean server_conf_sender, 374 I2Addr receiver, 375 OWPBoolean server_conf_receiver, 376 OWPTestSpec *test_spec 377 ); 378 379 extern OWPErrSeverity 380 _OWPTestSessionFree( 381 OWPTestSession tsession, 382 OWPAcceptType aval 383 ); 384 385 extern int 386 _OWPCreateSID( 387 OWPTestSession tsession 388 ); 389 390 /* 391 * This structure is used to hold the initial "fixed" 392 * fields in an owp file. Filled in with _OWPReadDataHeaderInitial(). 393 */ 394 typedef struct _OWPSessionHeaderInitialRec{ 395 /* 396 * File info, and fields for all versions 397 */ 398 OWPBoolean header; /* True if version >= 2 399 * indicates test req available 400 */ 401 struct stat sbuf; 402 uint32_t version; 403 uint32_t rec_size; 404 405 /* same as oset_datarecs for version >= 3 */ 406 off_t hdr_len; 407 408 /* 409 * Added for Version 2 (also test req) 410 */ 411 OWPSessionFinishedType finished; 412 413 /* 414 * Added for Version 3 415 */ 416 uint32_t next_seqno; 417 uint32_t num_skiprecs; 418 uint32_t num_datarecs; 419 420 off_t oset_skiprecs; 421 off_t oset_datarecs; 422 } _OWPSessionHeaderInitialRec, *_OWPSessionHeaderInitial; 423 424 extern OWPBoolean 425 _OWPReadDataHeaderInitial( 426 OWPContext ctx, 427 FILE *fp, 428 _OWPSessionHeaderInitial phdr 429 ); 430 431 extern OWPBoolean 432 _OWPWriteDataHeaderFinished( 433 OWPContext ctx, 434 FILE *fp, 435 uint32_t finished, 436 uint32_t next_seqno 437 ); 438 439 extern OWPBoolean 440 _OWPCleanDataRecs( 441 OWPContext cntrl, 442 OWPTestSession tptr, 443 uint32_t next_seqno, 444 OWPTimeStamp stoptime, 445 uint32_t *max_recv, /* out: max received index */ 446 off_t *off_start /* out: beginning of questionable data */ 447 ); 448 /* 449 * io.c prototypes 450 */ 451 extern int 452 _OWPSendBlocksIntr( 453 OWPControl cntrl, 454 uint8_t *buf, 455 int num_blocks, 456 int *retn_on_intr 457 ); 458 459 extern int 460 _OWPReceiveBlocksIntr( 461 OWPControl cntrl, 462 uint8_t *buf, 463 int num_blocks, 464 int *retn_on_intr 465 ); 466 467 extern int 468 _OWPSendBlocks( 469 OWPControl cntrl, 470 uint8_t *buf, 471 int num_blocks 472 ); 473 474 extern int 475 _OWPReceiveBlocks( 476 OWPControl cntrl, 477 uint8_t *buf, 478 int num_blocks 479 ); 480 481 extern int 482 _OWPEncryptBlocks( 483 OWPControl cntrl, 484 uint8_t *in_buf, 485 int num_blocks, 486 uint8_t *out_buf 487 ); 488 489 extern int 490 _OWPDecryptBlocks( 491 OWPControl cntrl, 492 uint8_t *in_buf, 493 int num_blocks, 494 uint8_t *out_buf 495 ); 496 497 extern void 498 _OWPMakeKey( 499 OWPControl cntrl, 500 uint8_t *binKey 501 ); 502 503 extern int 504 OWPEncryptToken( 505 const uint8_t *pf, 506 size_t pf_len, 507 const uint8_t salt[16], 508 uint32_t count, 509 const uint8_t token_in[_OWP_TOKEN_SIZE], 510 uint8_t token_out[_OWP_TOKEN_SIZE] 511 ); 512 513 extern int 514 OWPDecryptToken( 515 const uint8_t *pf, 516 size_t pf_len, 517 const uint8_t salt[16], 518 uint32_t count, 519 const uint8_t token_in[_OWP_TOKEN_SIZE], 520 uint8_t token_out[_OWP_TOKEN_SIZE] 521 ); 522 523 extern void 524 _OWPSendHMACAdd( 525 OWPControl cntrl, 526 const char *txt, 527 uint32_t num_blocks 528 ); 529 530 extern void 531 _OWPSendHMACDigestClear( 532 OWPControl cntrl, 533 char digest[16] 534 ); 535 536 extern void 537 _OWPRecvHMACAdd( 538 OWPControl cntrl, 539 const char *txt, 540 uint32_t num_blocks 541 ); 542 543 extern OWPBoolean 544 _OWPRecvHMACCheckClear( 545 OWPControl cntrl, 546 char check[16] 547 ); 548 549 /* 550 * protocol.c 551 */ 552 extern OWPErrSeverity 553 _OWPWriteServerGreeting( 554 OWPControl cntrl, 555 int *retn_on_intr, 556 uint32_t avail_modes, 557 uint8_t *challenge, /* [16] */ 558 uint8_t *salt, /* [16] */ 559 uint32_t count 560 ); 561 562 extern OWPErrSeverity 563 _OWPReadServerGreeting( 564 OWPControl cntrl, 565 int *retn_on_intr, 566 uint32_t *mode, /* modes available - returned */ 567 uint8_t *challenge, /* [16] : challenge - returned */ 568 uint8_t *salt, /* [16] : salt - returned */ 569 uint32_t *count 570 ); 571 572 extern OWPErrSeverity 573 _OWPWriteSetupResponse( 574 OWPControl cntrl, 575 int *retn_on_intr, 576 uint8_t *token /* [64] */ 577 ); 578 579 extern OWPErrSeverity 580 _OWPReadSetupResponse( 581 OWPControl cntrl, 582 int *retn_on_intr, 583 uint32_t *mode, 584 uint8_t *token, /* [32] - return */ 585 uint8_t *clientIV /* [16] - return */ 586 ); 587 588 extern OWPErrSeverity 589 _OWPWriteServerStart( 590 OWPControl cntrl, 591 int *retn_on_intr, 592 OWPAcceptType code, 593 OWPNum64 uptime 594 ); 595 596 extern OWPErrSeverity 597 _OWPReadServerStart( 598 OWPControl cntrl, 599 int *retn_on_intr, 600 OWPAcceptType *acceptval, /* ret */ 601 OWPNum64 *uptime_ret /* ret */ 602 ); 603 604 extern OWPErrSeverity 605 _OWPReadServerUptime( 606 OWPControl cntrl, 607 int *retn_on_intr, 608 OWPNum64 *uptime_ret 609 ); 610 611 extern int 612 _OWPEncodeTestRequestPreamble( 613 OWPContext ctx, 614 uint32_t *msg, 615 uint32_t *len_ret, 616 struct sockaddr *sender, 617 struct sockaddr *receiver, 618 OWPBoolean server_conf_sender, 619 OWPBoolean server_conf_receiver, 620 OWPSID sid, 621 OWPTestSpec *tspec 622 ); 623 624 extern OWPErrSeverity 625 _OWPDecodeTestRequestPreamble( 626 OWPContext ctx, 627 OWPBoolean request, 628 uint32_t *msg, 629 uint32_t msg_len, 630 struct sockaddr *sender, 631 struct sockaddr *receiver, 632 socklen_t *socklen, 633 uint8_t *ipvn, 634 OWPBoolean *server_conf_sender, 635 OWPBoolean *server_conf_receiver, 636 OWPSID sid, 637 OWPTestSpec *test_spec 638 ); 639 640 extern OWPErrSeverity 641 _OWPEncodeSlot( 642 uint32_t *msg, /* [4] - one block/ 16 bytes 32 bit aligned */ 643 OWPSlot *slot 644 ); 645 extern OWPErrSeverity 646 _OWPDecodeSlot( 647 OWPSlot *slot, 648 uint32_t *msg /* [4] - one block/ 16 bytes 32 bit aligned */ 649 ); 650 651 extern OWPErrSeverity 652 _OWPWriteTestRequest( 653 OWPControl cntrl, 654 int *retn_on_intr, 655 struct sockaddr *sender, 656 struct sockaddr *receiver, 657 OWPBoolean server_conf_sender, 658 OWPBoolean server_conf_receiver, 659 OWPSID sid, 660 OWPTestSpec *test_spec 661 ); 662 663 /* 664 * This function can be called from a server or client context. From the 665 * server it is reading an actual new request. From the client it is part 666 * of a FetchSession response. The server code MUST set the accept_ret 667 * pointer to a valid OWPAcceptType record. This record will be filled 668 * in with the appropriate AcceptType value for a response. The client 669 * code MUST set this to NULL. 670 */ 671 extern OWPErrSeverity 672 _OWPReadTestRequest( 673 OWPControl cntrl, 674 int *retn_on_intr, 675 OWPTestSession *test_session, 676 OWPAcceptType *accept_ret 677 ); 678 679 extern OWPBoolean 680 _OWPEncodeDataRecord( 681 char buf[_OWP_MAXDATAREC_SIZE], 682 OWPDataRec *rec 683 ); 684 685 extern OWPBoolean 686 _OWPDecodeDataRecord( 687 uint32_t file_version, 688 OWPDataRec *rec, 689 /* V0,V2 == [_OWP_DATARECV2_SIZE], V3 == [_OWP_DATAREC_SIZE] */ 690 char *buf 691 ); 692 693 extern OWPErrSeverity 694 _OWPWriteAcceptSession( 695 OWPControl cntrl, 696 int *retn_on_intr, 697 OWPAcceptType acceptval, 698 uint16_t port, 699 OWPSID sid 700 ); 701 702 extern OWPErrSeverity 703 _OWPReadAcceptSession( 704 OWPControl cntrl, 705 int *retn_on_intr, 706 OWPAcceptType *acceptval, 707 uint16_t *port, 708 OWPSID sid 709 ); 710 711 extern OWPErrSeverity 712 _OWPWriteStartSessions( 713 OWPControl cntrl, 714 int *retn_on_intr 715 ); 716 717 extern OWPErrSeverity 718 _OWPReadStartSessions( 719 OWPControl cntrl, 720 int *retn_on_intr 721 ); 722 723 extern void 724 _OWPEncodeSkipRecord( 725 uint8_t buf[_OWP_SKIPREC_SIZE], 726 OWPSkip skip 727 ); 728 729 extern void 730 _OWPDecodeSkipRecord( 731 OWPSkip skip, 732 char buf[_OWP_SKIPREC_SIZE] 733 ); 734 735 extern OWPErrSeverity 736 _OWPWriteStopSessions( 737 OWPControl cntrl, 738 int *retn_on_intr, 739 OWPAcceptType acceptval, 740 uint32_t num_sessions 741 ); 742 743 extern OWPErrSeverity 744 _OWPReadStopSessions( 745 OWPControl cntrl, 746 int *retn_on_intr, 747 OWPAcceptType *acceptval, 748 OWPTimeStamp stoptime 749 ); 750 751 extern OWPErrSeverity 752 _OWPWriteFetchSession( 753 OWPControl cntrl, 754 int *retn_on_intr, 755 uint32_t begin, 756 uint32_t end, 757 OWPSID sid 758 ); 759 760 extern OWPErrSeverity 761 _OWPReadFetchSession( 762 OWPControl cntrl, 763 int *retn_on_intr, 764 uint32_t *begin, 765 uint32_t *end, 766 OWPSID sid 767 ); 768 769 extern OWPErrSeverity 770 _OWPWriteFetchAck( 771 OWPControl cntrl, 772 int *retn_on_intr, 773 OWPAcceptType acceptval, 774 uint8_t finished, 775 uint32_t next_seqno, 776 uint32_t num_skiprecs, 777 uint32_t num_datarecs 778 ); 779 780 extern OWPErrSeverity 781 _OWPReadFetchAck( 782 OWPControl cntrl, 783 int *retn_on_intr, 784 OWPAcceptType *acceptval, 785 uint8_t *finished, 786 uint32_t *next_seqno, 787 uint32_t *num_skiprecs, 788 uint32_t *num_datarecs 789 ); 790 791 extern OWPErrSeverity 792 _OWPWriteStartAck( 793 OWPControl cntrl, 794 int *retn_on_intr, 795 OWPAcceptType acceptval 796 ); 797 798 extern OWPErrSeverity 799 _OWPReadStartAck( 800 OWPControl cntrl, 801 int *retn_on_intr, 802 OWPAcceptType *acceptval 803 ); 804 805 /* 806 * context.c 807 */ 808 809 extern OWPControl 810 _OWPControlAlloc( 811 OWPContext ctx, 812 OWPErrSeverity *err_ret 813 ); 814 815 extern OWPBoolean 816 _OWPCallGetPF( 817 OWPContext ctx, /* context record */ 818 const OWPUserID userid, /* identifies key */ 819 uint8_t **pf_ret, /* pass-phrase - return */ 820 size_t *pf_len, /* len - return */ 821 void **pf_free, /* free if set - return */ 822 OWPErrSeverity *err_ret /* error - return */ 823 ); 824 825 extern OWPBoolean 826 _OWPCallCheckControlPolicy( 827 OWPControl cntrl, /* control record */ 828 OWPSessionMode mode, /* requested mode */ 829 const char *userid, /* key identity */ 830 struct sockaddr *local_sa_addr, /* local addr or NULL */ 831 struct sockaddr *remote_sa_addr,/* remote addr */ 832 OWPErrSeverity *err_ret /* error - return */ 833 ); 834 835 extern OWPBoolean 836 _OWPCallCheckTestPolicy( 837 OWPControl cntrl, /* control handle */ 838 OWPBoolean local_sender, /* Is local send or recv */ 839 struct sockaddr *local, /* local endpoint */ 840 struct sockaddr *remote, /* remote endpoint */ 841 socklen_t sa_len, /* saddr sizes */ 842 OWPTestSpec *test_spec, /* test requested */ 843 void **closure, /* app data/per test */ 844 OWPErrSeverity *err_ret /* error - return */ 845 ); 846 847 extern OWPBoolean 848 _OWPCallCheckFetchPolicy( 849 OWPControl cntrl, /* control handle */ 850 struct sockaddr *local, /* local endpoint */ 851 struct sockaddr *remote, /* remote endpoint */ 852 socklen_t sa_len, /* saddr sizes */ 853 uint32_t begin, /* first seq_no */ 854 uint32_t end, /* last seq_no */ 855 OWPSID sid, /* sid */ 856 void **closure, /* app data/per test */ 857 OWPErrSeverity *err_ret /* error - return */ 858 ); 859 860 extern void 861 _OWPCallTestComplete( 862 OWPTestSession tsession, 863 OWPAcceptType aval 864 ); 865 866 /* 867 * non-NULL closure indicates "receiver" - NULL indicates R/O Fetch. 868 */ 869 extern FILE * 870 _OWPCallOpenFile( 871 OWPControl cntrl, /* control handle */ 872 void *closure, /* app data/per test */ 873 OWPSID sid, /* sid for datafile */ 874 char fname_ret[PATH_MAX+1] 875 ); 876 877 extern void 878 _OWPCallCloseFile( 879 OWPControl cntrl, 880 void *closure, 881 FILE *fp, 882 OWPAcceptType aval 883 ); 884 885 886 /* endpoint.c */ 887 888 /* 889 * The endpoint init function is responsible for opening a socket, and 890 * allocating a local port number. 891 * If this is a recv endpoint, it is also responsible for allocating a 892 * session id. 893 */ 894 extern OWPBoolean 895 _OWPEndpointInit( 896 OWPControl cntrl, 897 OWPTestSession tsession, 898 I2Addr localaddr, 899 FILE *fp, 900 OWPAcceptType *aval, 901 OWPErrSeverity *err_ret 902 ); 903 904 extern OWPBoolean 905 _OWPEndpointInitHook( 906 OWPControl cntrl, 907 OWPTestSession tsession, 908 OWPAcceptType *aval, 909 OWPErrSeverity *err_ret 910 ); 911 912 extern OWPBoolean 913 _OWPEndpointStart( 914 OWPEndpoint ep, 915 OWPErrSeverity *err_ret 916 ); 917 918 extern void 919 _OWPEndpointStatus( 920 OWPEndpoint ep, 921 OWPAcceptType *aval, 922 OWPErrSeverity *err_ret 923 ); 924 925 extern void 926 _OWPEndpointStop( 927 OWPEndpoint ep, 928 OWPAcceptType *aval, 929 OWPErrSeverity *err_ret 930 ); 931 932 extern void 933 _OWPEndpointFree( 934 OWPEndpoint ep, 935 OWPAcceptType *aval, 936 OWPErrSeverity *err_ret 937 ); 938 939 /* 940 * error.c 941 */ 942 extern OWPErrSeverity 943 _OWPFailControlSession( 944 OWPControl cntrl, 945 int err 946 ); 947 948 /* 949 * time.c 950 */ 951 952 extern int 953 _OWPInitNTP( 954 OWPContext ctx 955 ); 956 957 struct timespec * 958 _OWPGetTimespec( 959 OWPContext ctx, 960 struct timespec *ts, 961 uint32_t *esterr, 962 uint8_t *synchronized 963 ); 964 965 /* 966 * En/DecodeTimeStamp functions do not assume any alignment requirements 967 * for buf. (Most functions in protocol.c assume uint32_t alignment.) 968 */ 969 extern void 970 _OWPEncodeTimeStamp( 971 uint8_t buf[8], 972 OWPTimeStamp *tstamp 973 ); 974 extern OWPBoolean 975 _OWPEncodeTimeStampErrEstimate( 976 uint8_t buf[2], 977 OWPTimeStamp *tstamp 978 ); 979 extern void 980 _OWPDecodeTimeStamp( 981 OWPTimeStamp *tstamp, 982 uint8_t buf[8] 983 ); 984 extern OWPBoolean 985 _OWPDecodeTimeStampErrEstimate( 986 OWPTimeStamp *tstamp, 987 uint8_t buf[2] 988 ); 989 990 #endif /* OWAMPP_H */ 991