1 /* $Id$ 2 * -------------------------------------------------------------------------- 3 * 4 * //===== //===== ===//=== //===// // // //===// 5 * // // // // // // // // // 6 * //====// // // //===// // // //===<< 7 * // // // // // // // // 8 * ======// //===== // // //===== // //===// 9 * 10 * -------------- An SCTP implementation according to RFC 4960 -------------- 11 * 12 * Copyright (C) 2000 by Siemens AG, Munich, Germany. 13 * Copyright (C) 2001-2004 Andreas Jungmaier 14 * Copyright (C) 2004-2019 Thomas Dreibholz 15 * 16 * Acknowledgements: 17 * Realized in co-operation between Siemens AG and the University of 18 * Duisburg-Essen, Institute for Experimental Mathematics, Computer 19 * Networking Technology group. 20 * This work was partially funded by the Bundesministerium fuer Bildung und 21 * Forschung (BMBF) of the Federal Republic of Germany 22 * (Förderkennzeichen 01AK045). 23 * The authors alone are responsible for the contents. 24 * 25 * This library is free software: you can redistribute it and/or modify it 26 * under the terms of the GNU Lesser General Public License as published by 27 * the Free Software Foundation, either version 2.1 of the License, or 28 * (at your option) any later version. 29 * 30 * This library is distributed in the hope that it will be useful, 31 * but WITHOUT ANY WARRANTY; without even the implied warranty of 32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 * GNU General Public License for more details. 34 * 35 * You should have received a copy of the GNU Lesser General Public License 36 * along with this program. If not, see <http://www.gnu.org/licenses/>. 37 * 38 * Contact: sctp-discussion@sctp.de 39 * dreibh@iem.uni-due.de 40 * tuexen@fh-muenster.de 41 * andreas.jungmaier@web.de 42 */ 43 44 #ifndef SCTP_H 45 #define SCTP_H 46 47 48 /* Some important definitions for usage of reentrant versions. */ 49 #ifndef _REENTRANT 50 #define _REENTRANT 51 #endif 52 #ifndef _THREAD_SAFE 53 #define _THREAD_SAFE 54 #endif 55 #ifndef _GNU_SOURCE 56 #define _GNU_SOURCE 57 #endif 58 #ifndef USE_PTHREADS 59 #define USE_PTHREADS 60 #endif 61 62 63 #ifdef __cplusplus 64 extern "C" { 65 #endif 66 67 #define SCTP_MAJOR_VERSION 1 68 #define SCTP_MINOR_VERSION 0 69 #define SCTP_TINY_VERSION 8 70 71 /* the maximum length of an IP address string (IPv4 or IPv6, NULL terminated) */ 72 /* see RFC 1884 (mixed IPv6/Ipv4 addresses) */ 73 #define SCTP_MAX_IP_LEN 46 /* == INET6_ADDRSTRLEN */ 74 75 /** this parameter specifies the maximum number of addresses that an endpoint may have */ 76 #define SCTP_MAX_NUM_ADDRESSES 20 77 78 /* reasonable sized SACK, SCTP and IP header + one data chunk should be less than MTU */ 79 /* this is for ethernet..... ;-) */ 80 #define SCTP_MAXIMUM_DATA_LENGTH 1400 81 /******************** Defines *********************************************************************/ 82 /* the possible 7 states of an association */ 83 #define SCTP_CLOSED 0 84 #define SCTP_COOKIE_WAIT 1 85 #define SCTP_COOKIE_ECHOED 2 86 #define SCTP_ESTABLISHED 3 87 #define SCTP_SHUTDOWN_PENDING 4 88 #define SCTP_SHUTDOWN_RECEIVED 5 89 #define SCTP_SHUTDOWN_SENT 6 90 #define SCTP_SHUTDOWNACK_SENT 7 91 92 /* Pathstatus, used with networkstatus primitives */ 93 #define SCTP_PATH_OK 0 94 #define SCTP_PATH_UNREACHABLE 1 95 #define SCTP_PATH_ADDED 2 96 #define SCTP_PATH_REMOVED 3 97 #define SCTP_PATH_CONFIRMED 4 98 #define SCTP_PATH_UNCONFIRMED 5 99 100 101 /* for use in sctp_changeHeartBeat */ 102 #define SCTP_HEARTBEAT_ON 1 103 #define SCTP_HEARTBEAT_OFF 0 104 105 #define SCTP_UNORDERED_DELIVERY 1 106 #define SCTP_ORDERED_DELIVERY 0 107 108 /* boolean, 0==normal bundling, 1==do not bundle message */ 109 #define SCTP_BUNDLING_ENABLED 0 110 #define SCTP_BUNDLING_DISABLED 1 111 112 /* these are also for sctp_send() */ 113 #define SCTP_USE_PRIMARY -1 114 #define SCTP_INFINITE_LIFETIME 0xFFFFFFFF 115 #define SCTP_NO_RETRANSMISSION 0 116 #define SCTP_SEND_RELIABLE SCTP_INFINITE_LIFETIME 117 #define SCTP_NO_CONTEXT NULL 118 #define SCTP_GENERIC_PAYLOAD_PROTOCOL_ID 0 119 /* these are for sctp_receive() */ 120 #define SCTP_MSG_DEFAULT 0x00 121 #define SCTP_MSG_PEEK 0x02 122 123 #define SCTP_CHECKSUM_ALGORITHM_CRC32C 0x1 124 #define SCTP_CHECKSUM_ALGORITHM_ADLER32 0x2 125 126 /* Here are some error codes that are returned by some functions */ 127 /* this list may be enhanced or become more extensive in future releases */ 128 #define SCTP_SUCCESS 0 129 #define SCTP_LIBRARY_NOT_INITIALIZED -1 130 #define SCTP_INSTANCE_NOT_FOUND -2 131 #define SCTP_ASSOC_NOT_FOUND -3 132 #define SCTP_PARAMETER_PROBLEM -4 133 #define SCTP_MODULE_NOT_FOUND -5 134 #define SCTP_OUT_OF_RESOURCES -6 135 #define SCTP_NOT_SUPPORTED -7 136 #define SCTP_INSUFFICIENT_PRIVILEGES -8 137 #define SCTP_LIBRARY_ALREADY_INITIALIZED -9 138 #define SCTP_UNSPECIFIED_ERROR -10 139 #define SCTP_QUEUE_EXCEEDED -11 140 #define SCTP_WRONG_ADDRESS -12 141 #define SCTP_WRONG_STATE -13 142 #define SCTP_BUFFER_TOO_SMALL -14 143 #define SCTP_NO_CHUNKS_IN_QUEUE -15 144 #define SCTP_INSTANCE_IN_USE -16 145 #define SCTP_SPECIFIC_FUNCTION_ERROR 1 146 147 /* some constants for return codes from COMMUNICATION LOST or COMMUNICATION UP callbacks */ 148 #define SCTP_COMM_LOST_ABORTED 1 149 #define SCTP_COMM_LOST_ENDPOINT_UNREACHABLE 2 150 #define SCTP_COMM_LOST_EXCEEDED_RETRANSMISSIONS 3 151 #define SCTP_COMM_LOST_NO_TCB 4 152 /* maybe some others............. */ 153 #define SCTP_COMM_LOST_INVALID_PARAMETER 8 154 /* called if peer does not recognize some of our parameters */ 155 #define SCTP_COMM_LOST_FAILURE 9 156 #define SCTP_SHUTDOWN_COMPLETE 10 157 158 #define SCTP_COMM_UP_RECEIVED_VALID_COOKIE 1 159 #define SCTP_COMM_UP_RECEIVED_COOKIE_ACK 2 160 #define SCTP_COMM_UP_RECEIVED_COOKIE_RESTART 3 161 162 #define SCTP_SEND_QUEUE 1 163 164 165 /******************** Structure Definitions *******************************************************/ 166 167 168 typedef 169 /** 170 This struct containes the pointers to ULP callback functions. 171 Each SCTP-instance can have its own set of callback functions. 172 The callback functions of each SCTP-instance can be found by 173 first reading the datastruct of an association from the list of 174 associations. The datastruct of the association contains the name 175 of the SCTP instance to which it belongs. With the name of the SCTP- 176 instance its datastruct can be read from the list of SCTP-instances. 177 */ 178 struct SCTP_ulp_Callbacks 179 { 180 /* @{ */ 181 /** 182 * indicates that new data arrived from peer (chapter 10.2.A). 183 * @param 1 associationID 184 * @param 2 streamID 185 * @param 3 length of data 186 * @param 4 stream sequence number 187 * @param 5 tsn of (at least one) chunk belonging to the message 188 * @param 6 protocol ID 189 * @param 7 unordered flag (TRUE==1==unordered, FALSE==0==normal, numbered chunk) 190 * @param 8 pointer to ULP data 191 */ 192 void (*dataArriveNotif) (unsigned int, unsigned short, unsigned int, unsigned short, unsigned int, unsigned int, unsigned int, void*); 193 /** 194 * indicates a send failure (chapter 10.2.B). 195 * @param 1 associationID 196 * @param 2 pointer to data not sent 197 * @param 3 dataLength 198 * @param 4 pointer to context from sendChunk 199 * @param 5 pointer to ULP data 200 */ 201 void (*sendFailureNotif) (unsigned int, unsigned char *, unsigned int, unsigned int *, void*); 202 /** 203 * indicates a change of network status (chapter 10.2.C). 204 * @param 1 associationID 205 * @param 2 destinationAddresses 206 * @param 3 newState 207 * @param 4 pointer to ULP data 208 */ 209 void (*networkStatusChangeNotif) (unsigned int, short, unsigned short, void*); 210 /** 211 * indicates that a association is established (chapter 10.2.D). 212 * @param 1 associationID 213 * @param 2 status, type of event 214 * @param 3 number of destination addresses 215 * @param 4 number input streamns 216 * @param 5 number output streams 217 * @param 6 int supportPRSCTP (0=FALSE, 1=TRUE) 218 * @param 7 pointer to ULP data, usually NULL 219 * @return the callback is to return a pointer, that will be transparently returned with every callback 220 */ 221 void* (*communicationUpNotif) (unsigned int, int, unsigned int, 222 unsigned short, unsigned short, 223 int, void*); 224 /** 225 * indicates that communication was lost to peer (chapter 10.2.E). 226 * @param 1 associationID 227 * @param 2 status, type of event 228 * @param 3 pointer to ULP data 229 */ 230 void (*communicationLostNotif) (unsigned int, unsigned short, void*); 231 /** 232 * indicates that communication had an error. (chapter 10.2.F) 233 * Currently not implemented !? 234 * @param 1 associationID 235 * @param 2 status, type of error 236 * @param 3 pointer to ULP data 237 */ 238 void (*communicationErrorNotif) (unsigned int, unsigned short, void*); 239 /** 240 * indicates that a RESTART has occurred. (chapter 10.2.G) 241 * @param 1 associationID 242 * @param 2 pointer to ULP data 243 */ 244 void (*restartNotif) (unsigned int, void*); 245 /** 246 * indicates that a SHUTDOWN has been received by the peer. Tells the 247 * application to stop sending new data. 248 * @param 0 instanceID 249 * @param 1 associationID 250 * @param 2 pointer to ULP data 251 */ 252 void (*peerShutdownReceivedNotif) (unsigned int, void*); 253 /** 254 * indicates that a SHUTDOWN has been COMPLETED. (chapter 10.2.H) 255 * @param 0 instanceID 256 * @param 1 associationID 257 * @param 2 pointer to ULP data 258 */ 259 void (*shutdownCompleteNotif) (unsigned int, void*); 260 /** 261 * indicates that a queue length has exceeded (or length has dropped 262 * below) a previously determined limit 263 * @param 0 associationID 264 * @param 1 queue type (in-queue, out-queue, stream queue etc.) 265 * @param 2 queue identifier (maybe for streams ? 0 if not used) 266 * @param 3 queue length (either bytes or messages - depending on type) 267 * @param 4 pointer to ULP data 268 */ 269 void (*queueStatusChangeNotif) (unsigned int, int, int, int, void*); 270 /** 271 * indicates that a ASCONF request from the ULP has succeeded or failed. 272 * @param 0 associationID 273 * @param 1 correlation ID 274 * @param 2 result (int, negative for error) 275 * @param 3 pointer to a temporary, request specific structure (NULL if not needed) 276 * @param 4 pointer to ULP data 277 */ 278 void (*asconfStatusNotif) (unsigned int, unsigned int, int, void*, void*); 279 /* @} */ 280 }SCTP_ulpCallbacks; 281 282 283 typedef 284 /** 285 * This struct contains parameters that may be set globally with 286 * sctp_setLibraryParams(). For now, it only contains one flag. 287 */ 288 struct SCTP_Library_Parameters { 289 /** 290 * flag that controls whether an implementation will send 291 * ABORT chunks for OOTB SCTP packets, or whether it will 292 * silently discard these. In the later case, you will be 293 * able to run the implementation twice on one machine, without 294 * the two interfering with each other (also for tests on localhost) 295 * By default, this variable is set to TRUE (==1) 296 * Allowed values are 0 (==FALSE) or 1, else function will fail !! 297 */ 298 int sendOotbAborts; 299 /** 300 * This allows for globally setting the used checksum algorithm 301 * may be either 302 * - SCTP_CHECKSUM_ALGORITHM_CRC32C (0x1, default) or 303 * - SCTP_CHECKSUM_ALGORITHM_ADLER32 (0x2) 304 */ 305 int checksumAlgorithm; 306 /* 307 * Allowed values are 0 (==FALSE) or 1 (== TRUE) 308 */ 309 int supportPRSCTP; 310 /* 311 * Allowed values are 0 (==FALSE) or 1 (== TRUE) 312 */ 313 int supportADDIP; 314 315 316 }SCTP_LibraryParameters; 317 318 319 320 typedef 321 /** 322 * This struct contains some parameters that may be set or 323 * got with the sctp_getAssocDefaults()/sctp_setAssocDefaults() 324 * functions. So these may also be specified/retrieved for 325 * servers, before an association is established ! 326 */ 327 struct SCTP_Instance_Parameters { 328 /* @{ */ 329 /* this is read-only (get) */ 330 unsigned int noOfLocalAddresses; 331 /* this is read-only (get) */ 332 unsigned char localAddressList[SCTP_MAX_NUM_ADDRESSES][SCTP_MAX_IP_LEN]; 333 /** the initial round trip timeout */ 334 unsigned int rtoInitial; 335 /** the minimum timeout value */ 336 unsigned int rtoMin; 337 /** the maximum timeout value */ 338 unsigned int rtoMax; 339 /** the lifetime of a cookie */ 340 unsigned int validCookieLife; 341 /** (get/set) */ 342 unsigned short outStreams; 343 /** (get/set) */ 344 unsigned short inStreams; 345 /** does the instance by default signal unreliable streams (as a server) no==0, yes==1 */ 346 unsigned int supportUnreliableStreams; 347 /** does the instance by default signal unreliable streams (as a server) no==0, yes==1 */ 348 unsigned int supportADDIP; 349 /** maximum retransmissions per association */ 350 unsigned int assocMaxRetransmits; 351 /** maximum retransmissions per path */ 352 unsigned int pathMaxRetransmits; 353 /** maximum initial retransmissions */ 354 unsigned int maxInitRetransmits; 355 /** from recvcontrol : my receiver window */ 356 unsigned int myRwnd; 357 /** recvcontrol: delay for delayed ACK in msecs */ 358 unsigned int delay; 359 /** per instance: for the IP type of service field. */ 360 unsigned char ipTos; 361 /** limit the number of chunks queued in the send queue */ 362 unsigned int maxSendQueue; 363 /** currently unused, may limit the number of chunks queued in the receive queue later. 364 * Is this really needed ? The protocol limits the receive queue with 365 * window advertisement of arwnd==0 */ 366 unsigned int maxRecvQueue; 367 /** 368 * maximum number of associations we want. Is this limit greater than 0, 369 * implementation will automatically send ABORTs to incoming INITs, when 370 * there are that many associations ! 371 */ 372 unsigned int maxNumberOfAssociations; 373 /* @} */ 374 } SCTP_InstanceParameters; 375 376 377 typedef 378 /** 379 * This struct contains the data to be returned to the ULP with the 380 * sctp_getAssocStatus() function primitive. It is marked whether data 381 * may only be retrieved using the sctp_getAssocStatus() function, or 382 * also set using the sctp_setAssocStatus() function. 383 */ 384 struct SCTP_Association_Status 385 { 386 /* @{ */ 387 /** (get) */ 388 unsigned short state; 389 /** (get) */ 390 unsigned short numberOfAddresses; 391 /** (get) */ 392 unsigned char primaryDestinationAddress[SCTP_MAX_IP_LEN]; 393 /** (get) */ 394 unsigned short sourcePort; 395 /** (get) */ 396 unsigned short destPort; 397 /** (get) */ 398 unsigned short outStreams; 399 /** (get) */ 400 unsigned short inStreams; 401 /** does the assoc support unreliable streams no==0, yes==1 */ 402 unsigned int supportUnreliableStreams; 403 /** does the assoc support adding/deleting IP addresses no==0, yes==1 */ 404 unsigned int supportADDIP; 405 /** (get/set) */ 406 unsigned short primaryAddressIndex; 407 /** (get) */ 408 unsigned int currentReceiverWindowSize; 409 /** (get) */ 410 unsigned int outstandingBytes; 411 /** (get) */ 412 unsigned int noOfChunksInSendQueue; 413 /** (get) */ 414 unsigned int noOfChunksInRetransmissionQueue; 415 /** (get) */ 416 unsigned int noOfChunksInReceptionQueue; 417 /** (get/set) the initial round trip timeout */ 418 unsigned int rtoInitial; 419 /** (get/set) the minimum RTO timeout */ 420 unsigned int rtoMin; 421 /** (get/set) the maximum RTO timeout */ 422 unsigned int rtoMax; 423 /** (get/set) the lifetime of a cookie */ 424 unsigned int validCookieLife; 425 /** (get/set) maximum retransmissions per association */ 426 unsigned int assocMaxRetransmits; 427 /** (get/set) maximum retransmissions per path */ 428 unsigned int pathMaxRetransmits; 429 /** (get/set) maximum initial retransmissions */ 430 unsigned int maxInitRetransmits; 431 /** (get/set) from recvcontrol : my receiver window */ 432 unsigned int myRwnd; 433 /** (get/set) recvcontrol: delay for delayed ACK in msecs */ 434 unsigned int delay; 435 /** (get/set) per instance: for the IP type of service field. */ 436 unsigned char ipTos; 437 /** limit the number of chunks queued in the send queue */ 438 unsigned int maxSendQueue; 439 /** currently unused, may limit the number of chunks queued in the receive queue later. 440 * Is this really needed ? The protocol limits the receive queue with 441 * window advertisement of arwnd==0 */ 442 unsigned int maxRecvQueue; 443 /* @} */ 444 } SCTP_AssociationStatus; 445 446 447 typedef 448 /** 449 * this struct contains path specific parameters, so these 450 * values can only be retrieved/set, when the association 451 * already exists ! 452 */ 453 struct SCTP_Path_Status 454 { 455 /* @{ */ 456 /** */ 457 unsigned char destinationAddress[SCTP_MAX_IP_LEN]; 458 /** SCTP_PATH_ACTIVE 0, SCTP_PATH_INACTIVE 1 */ 459 short state; 460 /** smoothed round trip time in msecs */ 461 unsigned int srtt; 462 /** current rto value in msecs */ 463 unsigned int rto; 464 /** round trip time variation, in msecs */ 465 unsigned int rttvar; 466 /** defines the rate at which heartbeats are sent */ 467 unsigned int heartbeatIntervall; 468 /** congestion window size (flowcontrol) */ 469 unsigned int cwnd; 470 /** congestion window size 2 (flowcontrol) */ 471 unsigned int cwnd2; 472 /** Partial Bytes Acked (flowcontrol) */ 473 unsigned int partialBytesAcked; 474 /** Slow Start Threshold (flowcontrol) */ 475 unsigned int ssthresh; 476 /** from flow control */ 477 unsigned int outstandingBytesPerAddress; 478 /** Current MTU (flowcontrol) */ 479 unsigned int mtu; 480 /** per path ? per instance ? for the IP type of service field. */ 481 unsigned char ipTos; 482 /* @} */ 483 }SCTP_PathStatus; 484 485 486 /******************** Function Definitions ********************************************************/ 487 488 /** 489 * Function that needs to be called in advance to all library calls. 490 * It initializes all file descriptors etc. and sets up some variables 491 * @return 0 for success, 1 for adaptation level error, -1 if already called 492 * (i.e. the function has already been called before), -2 for insufficient rights 493 * (you need root-rights to open RAW sockets !). 494 */ 495 int sctp_initLibrary(void); 496 497 498 /** 499 * Function returns coded library version as result. This unsigned integer 500 * contains the major version in the upper 16 bits, and the minor version in 501 * the lower 16 bits. 502 * @return library version, or 0 (i.e. zero) as error ! 503 */ 504 unsigned int sctp_getLibraryVersion(void); 505 506 507 int sctp_registerInstance(unsigned short localPort, 508 unsigned short noOfInStreams, 509 unsigned short noOfOutStreams, 510 unsigned int noOfLocalAddresses, 511 unsigned char localAddressList[SCTP_MAX_NUM_ADDRESSES][SCTP_MAX_IP_LEN], 512 SCTP_ulpCallbacks ULPcallbackFunctions); 513 514 int sctp_unregisterInstance(unsigned short instance_name); 515 516 517 518 519 unsigned int sctp_associate(unsigned int SCTP_InstanceName, 520 unsigned short noOfOutStreams, 521 unsigned char destinationAddress[SCTP_MAX_IP_LEN], 522 unsigned short destinationPort, 523 void* ulp_data); 524 525 526 unsigned int sctp_associatex(unsigned int SCTP_InstanceName, 527 unsigned short noOfOutStreams, 528 unsigned char destinationAddresses[][SCTP_MAX_IP_LEN], 529 unsigned int noOfDestinationAddresses, 530 unsigned int maxSimultaneousInits, 531 unsigned short destinationPort, 532 void* ulp_data); 533 534 535 int sctp_shutdown(unsigned int associationID); 536 537 int sctp_abort(unsigned int associationID); 538 539 #ifndef SCTP_SOCKET_API 540 #define sctp_send sctp_send_private 541 #endif 542 int sctp_send_private(unsigned int associationID, 543 unsigned short streamID, 544 unsigned char *buffer, 545 unsigned int length, 546 unsigned int protocolId, 547 short path_id, /* -1 for primary path, else address index to be taken */ 548 void * context, /* SCTP_NO_CONTEXT */ 549 unsigned int lifetime, /* 0xFFFFFFFF-> infinite, 0->no retransmit, else msecs */ 550 int unorderedDelivery, /* use constants SCTP_ORDERED_DELIVERY, SCTP_UNORDERED_DELIVERY */ 551 int dontBundle); /* use constants SCTP_BUNDLING_ENABLED, SCTP_BUNDLING_DISABLED */ 552 553 554 /* 555 * sctp_receive() now returns SCTP_SUCCESS if data was received okay, 556 * also reports back a tsn value (at least one belonging to a fragment) 557 * SCTP_NO_CHUNKS_IN_QUEUE if there was no new data to be received, 558 * SCTP_PARAMETER_PROBLEM,SCTP_ASSOC_NOT_FOUND, SCTP_MODULE_NOT_FOUND if there was an error 559 */ 560 int sctp_receive(unsigned int associationID, unsigned short streamID, unsigned char *buffer, 561 unsigned int *length, unsigned short *streamSN, unsigned int * tsn, unsigned int flags); 562 563 564 int sctp_receivefrom(unsigned int associationID, unsigned short streamID, unsigned char *buffer, 565 unsigned int *length, unsigned short *streamSN, unsigned int * tsn, 566 unsigned int *addressIndex, unsigned int flags); 567 568 569 570 /*----------------------------------------------------------------------------------------------*/ 571 /* These are the new function for getting/setting parameters per instance, association or path */ 572 /*----------------------------------------------------------------------------------------------*/ 573 int sctp_setLibraryParameters(SCTP_LibraryParameters *params); 574 int sctp_getLibraryParameters(SCTP_LibraryParameters *params); 575 576 int sctp_setAssocDefaults(unsigned short SCTP_InstanceName, SCTP_InstanceParameters* params); 577 578 int sctp_getAssocDefaults(unsigned short SCTP_InstanceName, SCTP_InstanceParameters* params); 579 580 581 int sctp_getAssocStatus(unsigned int associationID, SCTP_AssociationStatus* status); 582 583 int sctp_setAssocStatus(unsigned int associationID, SCTP_AssociationStatus* new_status); 584 585 int sctp_getPathStatus(unsigned int associationID, short path_id, SCTP_PathStatus* status); 586 int sctp_setPathStatus(unsigned int associationID, short path_id, SCTP_PathStatus *new_status); 587 /*----------------------------------------------------------------------------------------------*/ 588 /* 589 * These _could_ be build up from the above functions, but for the sake of a 590 * complete API according to RFC 4960, section 10, we have the following 591 * six functions here, explicitly 592 */ 593 594 short sctp_setPrimary(unsigned int associationID, short path_id); 595 short sctp_getPrimary(unsigned int associationID); 596 597 int sctp_getSrttReport(unsigned int associationID, short path_id); 598 int sctp_changeHeartBeat(unsigned int associationID, 599 short path_id, int heartbeatON, unsigned int timeIntervall); 600 601 602 int sctp_requestHeartbeat(unsigned int associationID, short path_id); 603 604 int sctp_setFailureThreshold(unsigned int associationID, 605 unsigned short pathMaxRetransmissions); 606 607 /* 608 * this function can be used to get an instance ID of an association 609 * with the specified assocID 610 * @param associationID the association for which to get an instance id 611 * @param instanceID pointer to the instance ID value, contains valid value after 612 * a successful function call 613 * @return 0 for success, 1 if assoc does not exists, -1 for error (i.e. 614 * library not initialized, pointer Null, etc. 615 */ 616 int sctp_getInstanceID(unsigned int associationID, unsigned short* instanceID); 617 /*----------------------------------------------------------------------------------------------*/ 618 619 int sctp_receiveUnsent(unsigned int associationID, unsigned char *buffer, unsigned int *length, 620 unsigned int *tsn, unsigned short *streamID, unsigned short *streamSN, 621 unsigned int* protocolId, unsigned char* flags, void** context); 622 623 int sctp_receiveUnacked(unsigned int associationID, unsigned char *buffer, unsigned int *length, 624 unsigned int *tsn, unsigned short *streamID, unsigned short *streamSN, 625 unsigned int* protocolId,unsigned char* flags, void** context); 626 627 628 629 int sctp_deleteAssociation(unsigned int associationID); 630 631 632 /* Defines the callback function that is called when an event occurs 633 on an internal SCTP or UDP socket 634 Params: 1. file-descriptor of the socket 635 2. pointer to the datagram data, if any was received 636 3. length of datagram data, if any was received 637 4. source Address (as string, may be IPv4 or IPv6 address string, in numerical format) 638 5. source port number for UDP sockets, 0 for SCTP raw sockets 639 */ 640 typedef void (*sctp_socketCallback) (int, unsigned char *, int, unsigned char[] , unsigned short); 641 642 /* Defines the callback function that is called when an event occurs 643 on a user file-descriptor 644 Params: 1. file-descriptor 645 Params: 2. received events mask 646 Params: 3. pointer to registered events mask. It may be changed by the callback function. 647 Params: 4. user data 648 */ 649 typedef void (*sctp_userCallback) (int, short int, short int*, void*); 650 651 /** 652 * this function is supposed to open and bind a UDP socket listening on a port 653 * to incoming udp pakets on a local interface (a local union sockunion address) 654 * @param me local address string (IPv4 or IPv6, numerical format), if it receives UDP data 655 * it will trigger callback 656 * @param my_port port to receive data on (will bind that port !) 657 * @param scf callback funtion that is called when data has arrived 658 * @return new UDP socket file descriptor, or -1 if error ocurred 659 */ 660 #ifndef WIN32 661 int sctp_registerUdpCallback(unsigned char me[], 662 unsigned short my_port, 663 sctp_socketCallback scf); 664 665 int sctp_unregisterUdpCallback(int udp_sfd); 666 667 int sctp_sendUdpData(int sfd, unsigned char* buf, int length, 668 unsigned char destination[], unsigned short dest_port); 669 #endif 670 671 typedef void (*sctp_StdinCallback) (char*, int); 672 673 int sctp_registerStdinCallback(sctp_StdinCallback sdf, 674 char* buffer, int length); 675 676 int sctp_unregisterStdinCallback(); 677 678 /** 679 * this function registers a callback function for catching 680 * activity on a Unix file descriptor. We expect this to be useful 681 * in test programs mainly, so it is provided here for convenience. 682 * @param fd file-descriptor 683 * @param scf callback funtion that is called (when return is hit) 684 * @return 0, or -1 if error ocurred (i.e. already used) 685 */ 686 #ifndef WIN32 687 int sctp_registerUserCallback(int fd, sctp_userCallback sdf, void* userData, short int eventMask); 688 int sctp_unregisterUserCallback(int fd); 689 #endif 690 691 /* Defines the callback function that is called when an timer expires. 692 Params: 1. ID of timer 693 2. pointer to param1 694 3. pointer to param2 695 param1 and param2 are transparent data from the caller of start_timer, 696 that are returned to it when the timer expires. 697 */ 698 typedef void (*sctp_timerCallback) (unsigned int, void *, void *); 699 700 701 /** 702 * This function adds a callback that is to be called some time from now. It realizes 703 * the timer (in an ordered list). 704 * @param milliseconds action is to be started in milliseconds ms from now 705 * @param timer_cb pointer to a function to be executed, when timer expires 706 * @param param1 pointer to be returned to the caller when timer expires 707 * @param param2 pointer to be returned to the caller when timer expires 708 * @return returns an id value, that can be used to cancel a timer 709 * @author ajung 710 */ 711 unsigned int sctp_startTimer(unsigned int seconds , unsigned int microseconds, 712 sctp_timerCallback timer_cb, void *param1, void *param2); 713 714 715 /** 716 * This function stops a previously started timer. 717 * @param tid timer-id of timer to be removed 718 * @return returns 0 on success, 1 if tid not in the list, -1 on error 719 * @author ajung 720 */ 721 int sctp_stopTimer(unsigned int tid); 722 723 /** 724 * Restarts a timer currently running 725 * @param timer_id the value returned by set_timer for a certain timer 726 * @param milliseconds action is to be started in milliseconds ms from now 727 * @return new timer id , zero when there is an error (i.e. no timer) 728 * @author ajung 729 */ 730 unsigned int sctp_restartTimer(unsigned int timer_id, unsigned int seconds, unsigned int microseconds); 731 732 733 734 int sctp_getEvents(void); 735 736 int sctp_eventLoop(void); 737 738 int sctp_extendedEventLoop(void (*lock)(void* data), void (*unlock)(void* data), void* data); 739 740 /** 741 * these next funtions are unused. They should either be implemented, or removed :-) 742 * Maybe we should ask Thomas... 743 */ 744 int sctp_getNumberOfLocalAddresses(unsigned int associationID); 745 746 unsigned char* sctp_getLocalAddress(unsigned int associationID, int index); 747 748 749 #ifdef BAKEOFF 750 /* buffer points to a buffer that includes SCTP header. 751 This header will be overwritten by the function, and 752 insert correct data for an existing association */ 753 int sctp_sendRawData(unsigned int associationID, short path_id, 754 unsigned char *buffer, unsigned int length); 755 756 #endif 757 758 #ifdef TD_DEBUG 759 #warning Using memory allocation debugging functions! 760 #include <sys/types.h> 761 void* my_calloc(size_t nmemb, size_t size); 762 void* my_malloc(size_t size); 763 void my_free(void* p); 764 #define calloc my_calloc 765 #define malloc my_malloc 766 #define free my_free 767 #endif 768 769 #ifdef __cplusplus 770 } 771 #endif 772 773 774 #endif 775