Annotation of Gnu-Mach/chips/nw.h, revision 1.1.1.1

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
                      4:  * All Rights Reserved.
                      5:  * 
                      6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
                     11:  * 
                     12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     15:  * 
                     16:  * Carnegie Mellon requests users of this software to return to
                     17:  * 
                     18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
                     22:  * 
                     23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: 
                     27: #ifndef _NW_H_
                     28: #define _NW_H_ 1
                     29: 
                     30: #if defined(KMODE) || defined(KERNEL)
                     31: #include <sys/types.h> 
                     32: #include <mach/port.h> 
                     33: #else
                     34: #include "stub0.h"
                     35: #endif
                     36: 
                     37: /*** NETWORK APPLICATION PROGRAMMING INTERFACE ***/
                     38: 
                     39: /*** TYPES ***/
                     40: 
                     41: typedef enum {
                     42:   NW_SUCCESS,
                     43:   NW_FAILURE,
                     44:   NW_BAD_ADDRESS,
                     45:   NW_OVERRUN,
                     46:   NW_NO_CARRIER,
                     47:   NW_NOT_SERVER,
                     48:   NW_NO_EP,
                     49:   NW_BAD_EP,
                     50:   NW_INVALID_ARGUMENT,
                     51:   NW_NO_RESOURCES,
                     52:   NW_PROT_VIOLATION,
                     53:   NW_BAD_BUFFER,
                     54:   NW_BAD_LENGTH,
                     55:   NW_NO_REMOTE_EP,
                     56:   NW_TIME_OUT,
                     57:   NW_INCONSISTENCY,
                     58:   NW_ABORTED,
                     59:   NW_SYNCH,
                     60:   NW_QUEUED
                     61: } nw_result, *nw_result_t;
                     62: 
                     63: typedef enum {
                     64:   NW_INITIALIZE,
                     65:   NW_HOST_ADDRESS_REGISTER,
                     66:   NW_HOST_ADDRESS_UNREGISTER
                     67: } nw_update_type;
                     68: 
                     69: typedef enum {
                     70:   NW_STATUS,
                     71:   NW_HOST_ADDRESS_LOOKUP
                     72: } nw_lookup_type;
                     73: 
                     74: typedef u_int ip_address;
                     75: 
                     76: typedef u_int nw_address_1;
                     77: typedef u_int nw_address_2;
                     78: 
                     79: typedef struct {
                     80:   char name[20];          /*Host name -- first 19 characters, zero-terminated*/
                     81:   ip_address ip_addr;
                     82:   nw_address_1 nw_addr_1; /*4 most significant bits specify the device*/
                     83:   nw_address_2 nw_addr_2;
                     84: } nw_address_s, *nw_address_t;
                     85: 
                     86: typedef enum {
                     87:   NW_NULL,
                     88:   NW_IP,                 /*Virtual network for IP addresses*/
                     89:   NW_TCA100_1,           /*Fore Systems ATM network, first unit*/
                     90:   NW_TCA100_2            /*Fore Systems ATM network, second unit*/
                     91: } nw_device, *nw_device_t;
                     92: 
                     93: #define NW_DEVICE(addr) (addr >> 28)
                     94: 
                     95: typedef u_int nw_ep, *nw_ep_t;
                     96: 
                     97: typedef enum {
                     98:   NW_RAW,                      /*Raw service provided by network*/
                     99:   NW_DATAGRAM,                 /*Connectionless service*/
                    100:   NW_SEQ_PACKET,               /*Connection-oriented service*/
                    101:   NW_LINE                      /*Multiplexing line (system use only)*/
                    102: } nw_protocol;
                    103: 
                    104: typedef enum {
                    105:   NW_NO_ACCEPT,                /*Connection requests not accepted (client)*/
                    106:   NW_APPL_ACCEPT,              /*Connection requests received as message by
                    107:                                 application (msg_seqno 0), for examination
                    108:                                  and approval (nw_connection_accept function)*/
                    109:   NW_AUTO_ACCEPT,              /*Connection requests automatically accepted
                    110:                                 if endpoint is connection-oriented and
                    111:                                 not already connected*/
                    112:   NW_LINE_ACCEPT               /*Connection requests automatically accepted
                    113:                                 on a new endpoint (system use only)*/
                    114: } nw_acceptance;
                    115: 
                    116: typedef struct {
                    117:   nw_address_1 rem_addr_1;
                    118:   nw_address_2 rem_addr_2;
                    119:   nw_ep remote_ep:16;
                    120:   nw_ep local_ep:16;
                    121: } nw_peer_s, *nw_peer_t;
                    122: 
                    123: typedef struct nw_buffer {
                    124:   u_int buf_used:1;               /*Read-only for applications (always 1)*/
                    125:   u_int buf_length:31;            /*Read-only for applications*/
                    126:   struct nw_buffer *buf_next;     /*Used only to gather on sends*/
                    127:   u_int msg_seqno:10;             /*Sequential number of message,
                    128:                                    automatically set by network interface*/
                    129:   u_int block_offset:22;          /*Offset to the beginning of data (in bytes),
                    130:                                    from the start of the buffer*/
                    131:   u_int block_deallocate:1;       /*Used only to deallocate on sends*/
                    132:   u_int block_length:31;          /*Length of data (in bytes)
                    133:                                    beginning at offset*/
                    134:   nw_peer_s peer;                 /*Set on receives. Also required
                    135:                                    in first block on datagram sends.
                    136:                                    Ignored on sequenced packet sends.*/
                    137: } nw_buffer_s, *nw_buffer_t;
                    138: 
                    139: 
                    140: /* msg_seqno is normally between 1 and 1023, and increases modulo 1024
                    141:    (skipping 0) between consecutive messages. In sequenced packets, msg_seqno
                    142:    increases strictly by one. msg_seqno is assigned automatically.
                    143:    The network interface writes in the buffer the msg_seqno used,
                    144:    but only after the  buffer has been transmitted and, in case of 
                    145:    sequenced packet, acknowledged. The application can use this update
                    146:    to determine if a buffer can be reused, after a sending a message without
                    147:    the deallocate option.
                    148:    msg_seqno 0 is used when the corresponding send specifies the NW_URGENT 
                    149:    option. Such messages bypass any other messages possibly enqueued.
                    150:    msg_seqno 0 is also used for open connection requests, in the case
                    151:    of sequenced packet endpoints with the NW_APPL_ACCEPT option.
                    152:    The type of msg_seqno 0 message is differentiated by the first word in the
                    153:    message, which has type nw_options */
                    154: 
                    155: #define NW_BUFFER_ERROR ((nw_buffer_t) -1)      /*Used for error indication
                    156:                                                  other than buffer overrun
                    157:                                                  (for which NULL is used)*/
                    158: 
                    159: typedef enum {
                    160:   NW_INEXISTENT,
                    161:   NW_UNCONNECTED,
                    162:   NW_SIMPLEX_ORIGINATING,
                    163:   NW_SIMPLEX_ORIGINATED,
                    164:   NW_DUPLEX_ORIGINATING,
                    165:   NW_DUPLEX_ORIGINATING_2,
                    166:   NW_DUPLEX_ORIGINATED,
                    167:   NW_ORIGINATOR_CLOSING,
                    168:   NW_ORIGINATOR_RCLOSING,
                    169:   NW_ACCEPTING,
                    170:   NW_SIMPLEX_ACCEPTED,
                    171:   NW_DUPLEX_ACCEPTING,
                    172:   NW_DUPLEX_ACCEPTED,
                    173:   NW_ACCEPTOR_CLOSING,
                    174:   NW_ACCEPTOR_RCLOSING
                    175: } nw_state, *nw_state_t;
                    176: 
                    177: 
                    178: typedef enum nw_options {
                    179:   NW_NORMAL,
                    180:   NW_URGENT,
                    181:   NW_SYNCHRONIZATION                              /*System use only*/
                    182: } nw_options;
                    183: 
                    184: 
                    185: /*** FUNCTIONS ***/
                    186: 
                    187: extern nw_result nw_update(mach_port_t master_port, nw_update_type up_type,
                    188:                           int *up_info);
                    189: 
                    190: /*****************************************************************************
                    191:      Allows privileged applications to update network tables. The 
                    192:      application must present the device master port. up_type selects the
                    193:      type of update, and up_info is cast accordingly to the correct type.
                    194: 
                    195:      For NW_HOST_ADDRESS_REGISTER and NW_HOST_ADDRESS_UNREGISTER,
                    196:      up_info has type nw_address_t. For NW_HOST_ADDRESS_UNREGISTER,
                    197:      however, only the network address field is used.
                    198: 
                    199:      up_info is not used for NW_INITIALIZE. This option is used to 
                    200:      initialize network interface tables, but does not initialize
                    201:      devices. Initialization of hardware and network tables occurs
                    202:      automatically at probe/boot time, so this option is normally
                    203:      unnecessary.
                    204: 
                    205:      Returns NW_SUCCESS if operation completed successfully.
                    206:             NW_FAILURE if master port not presented.
                    207:             NW_NO_RESOURCES if network tables full (NW_HOST_ADDRESS_REGISTER).
                    208:             NW_BAD_ADDRESS if host not found (NW_HOST_ADDRESS_UNREGISTER).
                    209:             NW_INVALID_ARGUMENT if up_type is invalid or up_info is
                    210:                                 a bad pointer.
                    211:  *****************************************************************************/
                    212: 
                    213: 
                    214: extern nw_result nw_lookup(nw_lookup_type lt, int *look_info);
                    215: 
                    216: /*****************************************************************************
                    217:      Allows applications to lookup network tables. The type of 
                    218:      lookup is selected by lt, and look_info is cast to the correct type
                    219:      accordingly.
                    220: 
                    221:      For lt equal to NW_HOST_ADDRESS_LOOKUP, look_info has type
                    222:      nw_address_t. In this option, the host is looked up first using the
                    223:      IP address  as a key (if non-zero), then by name (if non-empty), 
                    224:      and finally by network address (if non-zero). The function
                    225:      returns NW_SUCCESS on the first match it finds, and sets the non-key
                    226:      fields of look_info to the values found. No consistency check is
                    227:      made if more than one key is supplied. The function returns
                    228:      NW_BAD_ADDRESS if the host was not found, and NW_INVALID_ARGUMENT
                    229:      if lt is invalid or look_info is a bad pointer.
                    230: 
                    231:      For lt equal to NW_STATUS, look_info has type nw_device_t on input
                    232:      and nw_result_t on output. The function returns NW_INVALID_ARGUMENT
                    233:      if the device chosen is invalid or look_info is a bad pointer;
                    234:      otherwise, the function returns NW_SUCCESS. look_info is
                    235:      set to: NW_FAILURE if the device is not present, NW_NOT_SERVER
                    236:      if the device is not serviced by this interface, or a
                    237:      device-dependent value otherwise (NW_SUCCESS if there is no device error).
                    238: 
                    239:  *****************************************************************************/
                    240: 
                    241: 
                    242: extern nw_result nw_endpoint_allocate(nw_ep_t epp, nw_protocol protocol,
                    243:                                      nw_acceptance accept, u_int buffer_size);
                    244: 
                    245: /*****************************************************************************
                    246:      Allocates a communication endpoint. On input, epp should point to the
                    247:      the endpoint number desired, or to 0 if any number is adequate.
                    248:      On output, epp points to the actual number allocated for the endpoint.
                    249:      protocol specifies the transport discipline applied to data transmitted
                    250:      or received through the endpoint. accept selects how open connection
                    251:      requests received for the endpoint should be handled (connection-oriented
                    252:      protocol), or whether the endpoint can receive messages (connectionless
                    253:      protocol). buffer_size specifies the length in bytes of the buffer area
                    254:      for data sent or received through the endpoint. 
                    255: 
                    256:      Returns NW_SUCCESS if endpoint successfully allocated.
                    257:              NW_INVALID_ARGUMENT if epp is a bad pointer or the
                    258:                                 protocol or accept arguments are invalid.
                    259:              NW_NO_EP if the endpoint name space is exhausted.
                    260:              NW_BAD_EP if there already is an endpoint with the
                    261:                       number selected, or the number selected is
                    262:                       out of bounds.
                    263:             NW_NO_RESOURCES if not enough memory for buffer.
                    264:  *****************************************************************************/
                    265:             
                    266: 
                    267: extern nw_result nw_endpoint_deallocate(nw_ep ep);
                    268: 
                    269: /*****************************************************************************
                    270:       Deallocates the given endpoint.
                    271: 
                    272:       Returns NW_SUCCESS if successfully deallocated endpoint.
                    273:               NW_BAD_EP if endpoint does not exist.
                    274:               NW_PROT_VIOLATION if access to endpoint not authorized.
                    275:  *****************************************************************************/
                    276: 
                    277: 
                    278: extern nw_buffer_t nw_buffer_allocate(nw_ep ep, u_int size);
                    279: 
                    280: /*****************************************************************************
                    281:       Allocates a buffer of the given size (in bytes) from the buffer area
                    282:       of the given endpoint.
                    283: 
                    284:       Returns NW_BUFFER_ERROR if endpoint does not exist or access to endpoint
                    285:                               is not authorized.
                    286:               NULL if no buffer with given size could be allocated.
                    287:              Pointer to allocated buffer, otherwise.
                    288:  *****************************************************************************/
                    289: 
                    290: 
                    291: extern nw_result nw_buffer_deallocate(nw_ep ep, nw_buffer_t buffer);
                    292: 
                    293: /*****************************************************************************
                    294:       Deallocates the given buffer.
                    295: 
                    296:       Returns NW_SUCCESS if successfully deallocated buffer.
                    297:               NW_BAD_EP if endpoint does not exist.
                    298:               NW_PROT_VIOLATION if access to endpoint not authorized.
                    299:              NW_BAD_BUFFER if buffer does not belong to endpoint's
                    300:                            buffer area or is malformed.
                    301:  *****************************************************************************/
                    302: 
                    303: 
                    304: extern nw_result nw_connection_open(nw_ep local_ep, nw_address_1 rem_addr_1,
                    305:                                    nw_address_2 rem_addr_2, nw_ep remote_ep);
                    306: 
                    307: /*****************************************************************************
                    308:       Opens a connection.
                    309: 
                    310:       Returns NW_SUCCESS if connection successfully opened.
                    311:               NW_BAD_EP if local endpoint does not exist, uses connectionless
                    312:                        protocol or is already connected.
                    313:               NW_PROT_VIOLATION if access to local or remote endpoint
                    314:                                not authorized.
                    315:              NW_BAD_ADDRESS if address of remote host is invalid.
                    316:              NW_NO_REMOTE_EP if connection name space exhausted at
                    317:                              remote host.
                    318:              NW_TIME_OUT if attempt to open connection timed out repeatedly.
                    319:              NW_FAILURE if remote endpoint does not exist, uses connectionless
                    320:                         protocol or is already connected, or if remote
                    321:                          application did not accept open request.
                    322:  *****************************************************************************/
                    323: 
                    324: 
                    325: extern nw_result nw_connection_accept(nw_ep ep, nw_buffer_t msg,
                    326:                                      nw_ep_t new_epp);
                    327: 
                    328: /*****************************************************************************
                    329:       Accepts open request (at the remote host). On input, new_epp equal to
                    330:       NULL indicates that the application does not accept the request.
                    331:       new_epp pointing to the value 0 indicates that the application wants
                    332:       to accept the connection on a new endpoint, created dynamically,
                    333:       with the same attributes as the original endpoint; new_epp pointing
                    334:       to the value ep indicates that the application wants to simply
                    335:       accept the open request. On output, new_epp points to the endpoint
                    336:       actually connected, if any. msg points to the open request, which is
                    337:       automatically deallocated. 
                    338: 
                    339:       Returns NW_SUCCESS if connection correctly accepted or refused.
                    340:               NW_BAD_EP if endpoint does not exist or has no outstanding
                    341:                          open request.
                    342:              NW_PROT_VIOLATION if access to endpoint not authorized.
                    343:              NW_BAD_BUFFER if msg does not belong to the endpoint's
                    344:                            buffer area, or is malformed.
                    345:              NW_INVALID_ARGUMENT if new_epp is a bad pointer or points to
                    346:                                  invalid value.
                    347:              NW_NO_EP if endpoint name space exhausted.
                    348:              NW_NO_RESOURCES if no buffer available for new endpoint.
                    349:              NW_TIME_OUT if attempt to accept at different endpoint
                    350:                            repeatedly timed out.
                    351:  *****************************************************************************/
                    352: 
                    353: 
                    354: extern nw_result nw_connection_close(nw_ep ep);
                    355: 
                    356: /*****************************************************************************
                    357:       Closes the endpoint's connection.
                    358: 
                    359:       Returns NW_SUCCESS if successfully closed connection.
                    360:               NW_BAD_EP if endpoint does not exist or is not connected.
                    361:               NW_PROT_VIOLATION if access to endpoint not authorized.
                    362:  *****************************************************************************/
                    363: 
                    364: 
                    365: extern nw_result nw_multicast_add(nw_ep local_ep, nw_address_1 rem_addr_1,
                    366:                                  nw_address_2 rem_addr_2, nw_ep remote_ep);
                    367: 
                    368: /*****************************************************************************
                    369:       Open multicast group or add one more member to multicast group.
                    370: 
                    371:       Returns NW_SUCCESS if successfully opened multicast group
                    372:                          or added member.
                    373:               NW_BAD_EP if local endpoint does not exist, uses connectionless
                    374:                        protocol or is already connected point-to-point.
                    375:               NW_PROT_VIOLATION if access to local or remote endpoint
                    376:                                not authorized.
                    377:              NW_BAD_ADDRESS if address of remote host is invalid.
                    378:              NW_NO_REMOTE_EP if connection name space exhausted at
                    379:                              remote host.
                    380:              NW_TIME_OUT if attempt to open or add to multicast
                    381:                          timed out repeatedly.
                    382:              NW_FAILURE if remote endpoint does not exist, uses connectionless
                    383:                         protocol or is already connected, or if remote
                    384:                          application did not accept open or add request.
                    385:  *****************************************************************************/
                    386: 
                    387: 
                    388: extern nw_result nw_multicast_drop(nw_ep local_ep, nw_address_1 rem_addr_1,
                    389:                                   nw_address_2 rem_addr_2, nw_ep remote_ep);
                    390: 
                    391: /*****************************************************************************
                    392:       Drop member from multicast group, or close group if last member.
                    393: 
                    394:       Returns NW_SUCCESS if successfully dropped member or closed group.
                    395:               NW_BAD_EP if local endpoint does not exist or is not connected in
                    396:                        multicast to the given remote endpoint.
                    397:               NW_PROT_VIOLATION if access to local endpoint not authorized.
                    398:  *****************************************************************************/
                    399: 
                    400: 
                    401: extern nw_result nw_endpoint_status(nw_ep ep, nw_state_t state,
                    402:                                    nw_peer_t peer);
                    403: 
                    404: /*****************************************************************************
                    405:       Returns the state of the given endpoint and peer to which it is 
                    406:       connected, if any. In case of multicast group, the first peer is
                    407:       returned.
                    408: 
                    409:       Returns NW_SUCCESS if status correctly returned.
                    410:               NW_BAD_EP if endpoint does not exist.
                    411:               NW_PROT_VIOLATION if access to endpoint not authorized.
                    412:              NW_INVALID_ARGUMENT if state or peer is a bad pointer.
                    413:  *****************************************************************************/
                    414: 
                    415: 
                    416: extern nw_result nw_send(nw_ep ep, nw_buffer_t msg, nw_options options);
                    417: 
                    418: /*****************************************************************************
                    419:       Sends message through endpoint with the given options.
                    420:       
                    421:       Returns NW_SUCCESS if message successfully queued for sending
                    422:                          (connectionless protocol) or sent and acknowledged
                    423:                         (connection-oriented protocol).
                    424:               NW_BAD_EP if endpoint does not exist or uses connection-oriented
                    425:                        protocol but is unconnected.
                    426:               NW_PROT_VIOLATION if access to endpoint not authorized.
                    427:              NW_BAD_BUFFER if msg (or one of the buffers linked by buf_next)
                    428:                            is not a buffer in the endpoint's buffer area, or
                    429:                             is malformed (e.g., block_length extends beyond
                    430:                             end of buffer).
                    431:              NW_NO_RESOURCES if unable to queue message due to resource
                    432:                              exhaustion.
                    433:              NW_BAD_LENGTH if the total message length is too long for the
                    434:                             network and protocol used.
                    435:              NW_BAD_ADDRESS if address of remote host is invalid
                    436:                             (connectionless protocol).
                    437:              NW_FAILURE if repeated errors in message transmission
                    438:                         (connection-oriented).
                    439:              NW_TIME_OUT if repeated time-outs in message transmission
                    440:                          (connection-oriented).
                    441:              NW_OVERRUN if no buffer available in receiver's buffer area.
                    442:                          (connection-oriented).
                    443:  *****************************************************************************/
                    444: 
                    445: 
                    446: extern nw_buffer_t nw_receive(nw_ep ep, int time_out);
                    447: 
                    448: /*****************************************************************************
                    449:       Receive message destined to endpoint. Return if request  not
                    450:       satisfied within time_out msec. time_out 0 means non-blocking receive,
                    451:       while -1 means block indefinitely.
                    452: 
                    453:       Returns NW_BUFFER_ERROR if endpoint does not exist or access
                    454:                               to endpoint is not authorized.
                    455:              NULL if no message available for reception within the
                    456:                   specified time-out period.
                    457:              Pointer to message, otherwise.
                    458:  *****************************************************************************/
                    459: 
                    460: 
                    461: extern nw_buffer_t nw_rpc(nw_ep ep, nw_buffer_t send_msg, nw_options options,
                    462:                          int time_out);
                    463: 
                    464: /*****************************************************************************
                    465:       Send message through given endpoint with given options and then
                    466:       receive message through the same endpoint. Receive waiting time
                    467:       is limited to time_out msec.
                    468: 
                    469:       Returns NW_BUFFER_ERROR if endpoint does not exist, access to
                    470:                               endpoint is not authorized, or there was
                    471:                              some transmission error.
                    472:              NULL if no message available for reception within the
                    473:                   specified time-out period.
                    474:              Pointer to message received, otherwise.
                    475:  *****************************************************************************/
                    476: 
                    477: 
                    478: extern nw_buffer_t nw_select(u_int nep, nw_ep_t epp, int time_out);
                    479: 
                    480: /*****************************************************************************
                    481:       Receive message from one of the nep endpoints in the array epp.
                    482:       Waiting time is limited to time_out msec.
                    483: 
                    484:       Returns NW_BUFFER_ERROR if epp does not point to a valid array of nep
                    485:                               endpoint numbers, one of the endpoints does
                    486:                               not exist or has restricted access or the request
                    487:                              could not be correctly queued because of resource
                    488:                              exhaustion.
                    489:              NULL if no message arrived within the specified time-out period.
                    490:              Pointer to message received, otherwise.
                    491:  *****************************************************************************/
                    492: 
                    493: 
                    494: #endif /* _NW_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.