Tech-invite3GPPspaceIETFspace
959493929190898887868584838281807978777675747372717069686766656463626160595857565554535251504948474645444342414039383736353433323130292827262524232221201918171615141312111009080706050403020100
in Index   Prev   Next

RFC 1002

Protocol standard for a NetBIOS service on a TCP/UDP transport: Detailed specifications

Pages: 84
Internet Standard: 19
Errata
STD 19 is also:  1001
Part 3 of 3 – Pages 67 to 84
First   Prev   None

Top   ToC   RFC1002 - Page 67   prevText
5.2.  SESSION SERVICE PROTOCOLS

   The following are variables and should be configurable by the
   NetBIOS user.  The default values of these variables is found in
   "Defined Constants and Variables" in the Detailed
   Specification.):

   - SSN_RETRY_COUNT - The maximum number TCP connection attempts
     allowable per a single NetBIOS call request.

   - SSN_CLOSE_TIMEOUT is the time period to wait when closing the
     NetBIOS session before killing the TCP connection if session
     sends are outstanding.

   The following are Defined Constants for the NetBIOS Session
   Service.  (See "Defined Constants and Variables" in the Detailed
   Specification for the value of these constants):

   - SSN_SRVC_TCP_PORT - is the globally well-known TCP port
     allocated for the NetBIOS Session Service.  The service accepts
     TCP connections on this port to establish NetBIOS Sessions.
     The TCP connection established to this port by the caller is
     initially used for the exchange of NetBIOS control information.
     The actual NetBIOS data connection may also pass through this
     port or, through the retargetting facility, through another
     port.

5.2.1.  SESSION ESTABLISHMENT PROTOCOLS

5.2.1.1.  USER REQUEST PROCESSING

   PROCEDURE listen(listening name, caller name)
   /*
    * User initiated processing for B, P and M nodes
    *
    * This procedure assumes that an incoming session will be
    * retargetted here by a session server.
    */
   BEGIN
        Do TCP listen; /* Returns TCP port used */
        Register listen with Session Service, give names and
             TCP port;

        Wait for TCP connection to open;   /* Incoming call */

        Read SESSION REQUEST packet from connection

        Process session request (see section on
             processing initiated by the reception of session
             service packets);
Top   ToC   RFC1002 - Page 68
        Inform Session Service that NetBIOS listen is complete;

        IF session established THEN
             return success and session information to user;
        ELSE
             return failure;
   END /* procedure */

   PROCEDURE call(calling name, called name)
   /*
    * user initiated processing for B, P and M nodes
    */

   /*
    * This algorithm assumes that the called name is a unique name.
    * If the called name is a group name, the call() procedure
    * needs to cycle through the members of the group
    * until either (retry_count == SSN_RETRY_COUNT) or
    * the list has been exhausted.
    */
   BEGIN
        retry_count = 0;
        retarget = FALSE;   /* TRUE: caller is being retargetted */
        name_query = TRUE;  /* TRUE: caller must begin again with */
                            /*       name query. */

        REPEAT
             IF name_query THEN
             BEGIN
                  do name discovery, returns IP address;
                  TCP port = SSN_SRVC_TCP_PORT;

                  IF name discovery fails THEN
                       return failure;
                  ELSE
                       name_query = FALSE;
             END

             /*
              * now have IP address and TCP port of
              * remote party.
              */

             establish TCP connection with remote party, use an
                  ephemeral port as source TCP port;
             IF connection refused THEN
             BEGIN
                  IF retarget THEN
                  BEGIN
                       /* retry */
                       retarget = FALSE;
Top   ToC   RFC1002 - Page 69
                       use original IP address and TCP port;
                       goto LOOP;
                  END

                  /* retry for just missed TCP listen */

                  pause(SESSION_RETRY_TIMER);
                  establish TCP connection, again use ephemeral
                       port as source TCP port;

                  IF connection refused OR
                     connection timed out THEN
                       return failure;
             END
             ELSE
             IF connection timed out THEN
             BEGIN
                  IF retarget THEN
                  BEGIN
                       /* retry */
                       retarget = FALSE;
                       use original IP address and TCP port;
                       goto LOOP;
                  END
                  ELSE
                  BEGIN
                       /*
                        * incorrect name discovery was done,
                        * try again
                        */

                       inform name discovery process of
                            possible error;
                       name_query = TRUE;
                       goto LOOP;
                  END
             END

             /*
              * TCP connection has been established
              */

             wait for session response packet;
             CASE packet type OF

                POSITIVE SESSION RESPONSE:
                  return success and session established
                       information;

                NEGATIVE SESSION RESPONSE:
                BEGIN
Top   ToC   RFC1002 - Page 70
                  CASE error OF
                     NOT LISTENING ON CALLED NAME:
                     NOT LISTENING FOR CALLING NAME:
                     BEGIN
                       kill TCP connection;
                       return failure;
                     END

                     CALLED NAME NOT PRESENT:
                     BEGIN
                       /*
                        * called name does not exist on
                        * remote node
                        */

                       inform name discovery procedure
                            of possible error;

                       IF this is a P or M node THEN
                       BEGIN
                            /*
                             * Inform NetBIOS Name Server
                             * it has returned incorrect
                             * information.
                             */
                            send NAME RELEASE REQUEST for called
                              name and IP address to
                              NetBIOS Name Server;
                       END
                       /* retry from beginning */
                       retarget = FALSE;
                       name_query = TRUE;
                       goto LOOP;
                     END /* called name not present */
                  END /* case */
                END /* negative response */

                RETARGET SESSION RESPONSE:
                BEGIN
                  close TCP connection;
                  extract IP address and TCP port from
                       response;
                  retarget = TRUE;
                END /* retarget response */
             END /* case */

   LOOP:          retry_count = retry_count + 1;

        UNTIL (retry_count > SSN_RETRY_COUNT);
        return failure;
   END /* procedure */
Top   ToC   RFC1002 - Page 71
5.2.1.2.  RECEIVED PACKET PROCESSING

   These are packets received on a TCP connection before a session
   has been established.  The listen routines attached to a NetBIOS
   user process need not implement the RETARGET response section.
   The user process version, separate from a shared Session Service,
   need only accept (POSITIVE SESSION RESPONSE) or reject (NEGATIVE
   SESSION RESPONSE) a session request.

   PROCEDURE session_packet(packet)
   /*
    * processing initiated by receipt of a session service
    * packet for a session in the session establishment phase.
    * Assumes the TCP connection has been accepted.
    */
   BEGIN
        CASE packet type

           SESSION REQUEST:
           BEGIN
             IF called name does not exist on node THEN
             BEGIN
                  send NEGATIVE SESSION RESPONSE with CALLED
                       NAME NOT PRESENT error code;
                  close TCP connection;
             END

             Search for a listen with CALLING NAME for CALLED
                  NAME;
             IF matching listen is found THEN
             BEGIN
                  IF port of listener process is port TCP
                     connection is on THEN
                  BEGIN
                       send POSITIVE SESSION RESPONSE;

                       Hand off connection to client process
                            and/or inform user session is
                            established;
                  END
                  ELSE
                  BEGIN
                       send RETARGET SESSION RESPONSE with
                            listener's IP address and
                            TCP port;
                       close TCP connection;
                  END
             END
             ELSE
             BEGIN
                  /* no matching listen pending */
Top   ToC   RFC1002 - Page 72
                  send NEGATIVE SESSION RESPONSE with either
                       NOT LISTENING ON CALLED NAME or NOT
                       LISTENING FOR CALLING NAME error
                       code;
                  close TCP connection;
             END
           END /* session request */
        END /* case */
   END /* procedure */

5.2.2.  SESSION DATA TRANSFER PROTOCOLS

5.2.2.1.  USER REQUEST PROCESSING

   PROCEDURE send_message(user_message)
   BEGIN
        build SESSION MESSAGE header;
        send SESSION MESSAGE header;
        send user_message;
        reset and restart keep-alive timer;
        IF send fails THEN
        BEGIN
             /*
              * TCP connection has failed */
              */
             close NetBIOS session;
             inform user that session is lost;
             return failure;
        END
        ELSE
             return success;
   END

5.2.2.2.  RECEIVED PACKET PROCESSING

   These are packets received after a session has been established.

   PROCEDURE session_packet(packet)
   /*
    * processing initiated by receipt of a session service
    * packet for a session in the data transfer phase.
    */
   BEGIN
        CASE packet type OF

           SESSION  MESSAGE:
           BEGIN
             process message header;
             read in user data;
             reset and restart keep-alive timer;
             deliver data to user;
Top   ToC   RFC1002 - Page 73
           END /* session message */

           SESSION KEEP ALIVE:
             discard packet;

        END /* case */
   END /* procedure */

5.2.2.3.  PROCESSING INITIATED BY TIMER

   PROCEDURE session_ka_timer()
   /*
    * processing initiated when session keep alive timer expires
    */
   BEGIN
            send SESSION KEEP ALIVE, if configured;
            IF send fails THEN
            BEGIN
             /* remote node, or path to it, is down */

             abort TCP connection;
             close NetBIOS session;
             inform user that session is lost;
             return;
            END
   END /* procedure */

5.2.3.  SESSION TERMINATION PROTOCOLS

5.2.3.1.  USER REQUEST PROCESSING

   PROCEDURE close_session()

   /* initiated by a user request to close a session */

   BEGIN
        close gracefully the TCP connection;

        WAIT for the connection to close or SSN_CLOSE_TIMEOUT
             to expire;

        IF time out expired THEN
             abort TCP connection;
   END /* procedure */

5.2.3.2.  RECEPTION INDICATION PROCESSING

   PROCEDURE close_indication()
   /*
    * initiated by a TCP indication of a close request from
    * the remote connection partner.
Top   ToC   RFC1002 - Page 74
    */
   BEGIN
        close gracefully TCP connection;

        close NetBIOS session;

        inform user session closed by remote partner;
   END /* procedure */

5.3.  NetBIOS DATAGRAM SERVICE PROTOCOLS

   The following are GLOBAL variables and should be NetBIOS user
   configurable:

   - SCOPE_ID: the non-leaf section of the domain name preceded by a
     '.'  which represents the domain of the NetBIOS scope for the
     NetBIOS name.  The following protocol description only supports
     single scope operation.

   - MAX_DATAGRAM_LENGTH: the maximum length of an IP datagram.  The
     minimal maximum length defined in for IP is 576 bytes.  This
     value is used when determining whether to fragment a NetBIOS
     datagram.  Implementations are expected to be capable of
     receiving unfragmented NetBIOS datagrams up to their maximum
     size.

   - BROADCAST_ADDRESS: the IP address B-nodes use to send datagrams
     with group name destinations and broadcast datagrams.  The
     default is the IP broadcast address for a single IP network.


   The following are Defined Constants for the NetBIOS Datagram
   Service:

   - DGM_SRVC_UDP_PORT: the globally well-known UDP port allocated
     where the NetBIOS Datagram Service receives UDP packets.  See
     section 6, "Defined Constants", for its value.

5.3.1.  B NODE TRANSMISSION OF NetBIOS DATAGRAMS

   PROCEDURE send_datagram(data, source, destination, broadcast)

   /*
    * user initiated processing on B node
    */

   BEGIN
        group = FALSE;

        do name discovery on destination name, returns name type and
             IP address;
Top   ToC   RFC1002 - Page 75
        IF name type is group name THEN
        BEGIN
             group = TRUE;
        END

        /*
         * build datagram service UDP packet;
         */
        convert source and destination NetBIOS names into
             half-ASCII, biased encoded name;
        SOURCE_NAME = cat(source, SCOPE_ID);
        SOURCE_IP = this nodes IP address;
        SOURCE_PORT =  DGM_SRVC_UDP_PORT;

        IF NetBIOS broadcast THEN
        BEGIN
             DESTINATION_NAME = cat("*", SCOPE_ID)
        END
        ELSE
        BEGIN
             DESTINATION_NAME = cat(destination, SCOPE_ID)
        END

        MSG_TYPE = select_one_from_set
             {BROADCAST, DIRECT_UNIQUE, DIRECT_GROUP}
        DGM_ID = next transaction id for Datagrams;
        DGM_LENGTH = length of data + length of second level encoded
             source and destination names;

        IF (length of the NetBIOS Datagram, including UDP and
            IP headers, > MAX_DATAGRAM_LENGTH) THEN
        BEGIN
             /*
              * fragment NetBIOS datagram into 2 UDP packets
              */
             Put names into 1st UDP packet and any data that fits
                  after names;
             Set MORE and FIRST bits in 1st UDP packet's FLAGS;
             OFFSET in 1st UDP = 0;

             Replicate NetBIOS Datagram header from 1st UDP packet
                  into 2nd UDP packet;
             Put rest of data in 2nd UDP packet;
             Clear MORE and FIRST bits in 2nd UDP packet's FLAGS;
             OFFSET in 2nd UDP = DGM_LENGTH - number of name and
                  data bytes in 1st UDP;
        END
        BEGIN
             /*
              * Only need one UDP packet
              */
Top   ToC   RFC1002 - Page 76
             USER_DATA = data;
             Clear MORE bit and set FIRST bit in FLAGS;
             OFFSET = 0;
        END

        IF (group == TRUE) OR (NetBIOS broadcast) THEN
        BEGIN
             send UDP packet(s) to BROADCAST_ADDRESS;
        END
        ELSE
        BEGIN
             send UDP packet(s) to IP address returned by name
                discovery;
        END
   END /* procedure */

5.3.2.  P AND M NODE TRANSMISSION OF NetBIOS DATAGRAMS

   PROCEDURE send_datagram(data, source, destination, broadcast)

   /*
    * User initiated processing on P and M node.
    *
    * This processing is the same as for B nodes except for
    * sending broadcast and multicast NetBIOS datagrams.
    */

   BEGIN
        group = FALSE;

        do name discovery on destination name, returns name type
             and IP address;
        IF name type is group name THEN
        BEGIN
             group = TRUE;
        END

        /*
         * build datagram service UDP packet;
         */
        convert source and destination NetBIOS names into
             half-ASCII, biased encoded name;
        SOURCE_NAME = cat(source, SCOPE_ID);
        SOURCE_IP = this nodes IP address;
        SOURCE_PORT =  DGM_SRVC_UDP_PORT;

        IF NetBIOS broadcast THEN
        BEGIN
             DESTINATION_NAME = cat("*", SCOPE_ID)
        END
        ELSE
Top   ToC   RFC1002 - Page 77
        BEGIN
             DESTINATION_NAME = cat(destination, SCOPE_ID)
        END

        MSG_TYPE = select_one_from_set
             {BROADCAST, DIRECT_UNIQUE, DIRECT_GROUP}
        DGM_ID = next transaction id for Datagrams;
        DGM_LENGTH = length of data + length of second level encoded
             source and destination names;

        IF (length of the NetBIOS Datagram, including UDP and
            IP headers, > MAX_DATAGRAM_LENGTH) THEN
        BEGIN
             /*
              * fragment NetBIOS datagram into 2 UDP packets
              */
             Put names into 1st UDP packet and any data that fits
                  after names;
             Set MORE and FIRST bits in 1st UDP packet's FLAGS;

             OFFSET in 1st UDP = 0;

             Replicate NetBIOS Datagram header from 1st UDP packet
                  into 2nd UDP packet;
             Put rest of data in 2nd UDP packet;
             Clear MORE and FIRST bits in 2nd UDP packet's FLAGS;
             OFFSET in 2nd UDP = DGM_LENGTH - number of name and
                  data bytes in 1st UDP;
        END
        BEGIN
             /*
              * Only need one UDP packet
              */
             USER_DATA = data;
             Clear MORE bit and set FIRST bit in FLAGS;
             OFFSET = 0;
        END

        IF (group == TRUE) OR (NetBIOS broadcast) THEN
        BEGIN
             /*
              * Sending of following query is optional.
              * Node may send datagram to NBDD immediately
              * but NBDD may discard the datagram.
              */
             send DATAGRAM QUERY REQUEST to NBDD;
             IF response is POSITIVE QUERY RESPONSE THEN
                  send UDP packet(s) to NBDD Server IP address;
             ELSE
             BEGIN
                  get list of destination nodes from NBNS;
Top   ToC   RFC1002 - Page 78
                  FOR EACH node in list
                  BEGIN
                       send UDP packet(s) to this node's
                            IP address;
                  END
             END
        END
        ELSE
        BEGIN
             send UDP packet(s) to IP address returned by name
                discovery;
   END /* procedure */

5.3.3.  RECEPTION OF NetBIOS DATAGRAMS BY ALL NODES

   The following algorithm discards out of order NetBIOS Datagram
   fragments.  An implementation which reassembles out of order
   NetBIOS Datagram fragments conforms to this specification.  The
   fragment discard timer is initialized to the value FRAGMENT_TO.
   This value should be user configurable.  The default value is
   given in Section 6, "Defined Constants and Variables".

   PROCEDURE datagram_packet(packet)

   /*
    * processing initiated by datagram packet reception
    * on B, P and M nodes
    */
   BEGIN
        /*
         * if this node is a P node, ignore
         * broadcast packets.
         */

        IF this is a P node AND incoming packet is
             a broadcast packet THEN
        BEGIN
             discard packet;
        END

        CASE packet type OF

           DATAGRAM SERVICE:
           BEGIN
             IF FIRST bit in FLAGS is set THEN
             BEGIN
                  IF MORE bit in FLAGS is set THEN
                  BEGIN
                       Save 1st UDP packet of the Datagram;
                       Set this Datagram's fragment discard
                         timer to FRAGMENT_TO;
Top   ToC   RFC1002 - Page 79
                       return;
                  END
                  ELSE
                       Datagram is composed of a single
                         UDP packet;
             END
             ELSE
             BEGIN
                  /* Have the second fragment of a Datagram */

                  Search for 1st fragment by source IP address
                     and DGM_ID;
                  IF found 1st fragment THEN
                       Process both UDP packets;
                  ELSE
                  BEGIN
                       discard 2nd fragment UDP packet;
                       return;
                  END
             END

             IF DESTINATION_NAME is '*' THEN
             BEGIN
                  /* NetBIOS broadcast */

                  deliver USER_DATA from UDP packet(s) to all
                       outstanding receive broadcast
                       datagram requests;
                  return;
             END
             ELSE
             BEGIN /* non-broadcast */
                  /* Datagram for Unique or Group Name */

                  IF DESTINATION_NAME is not present in the
                     local name table THEN
                  BEGIN
                       /* destination not present */
                       build DATAGRAM ERROR packet, clear
                            FIRST and MORE bit, put in
                            this nodes IP and PORT, set
                            ERROR_CODE;
                       send DATAGRAM ERROR packet to
                            source IP address and port
                            of UDP;
                       discard UDP packet(s);
                       return;
                  END
                  ELSE
                  BEGIN /* good */
                       /*
Top   ToC   RFC1002 - Page 80
                        * Replicate received NetBIOS datagram for
                        * each recipient
                        */
                       FOR EACH pending NetBIOS user's receive
                            datagram operation
                       BEGIN
                            IF source name of operation
                               matches destination name
                               of packet THEN
                            BEGIN
                               deliver USER_DATA from UDP
                                 packet(s);
                            END
                       END /* for each */
                       return;
                  END /* good */
             END /* non-broadcast */
            END /* datagram service */

           DATAGRAM ERROR:
           BEGIN
                /*
                 * name service returned incorrect information
                 */

                inform local name service that incorrect
                  information was provided;

                IF this is a P or M node THEN
                BEGIN
                     /*
                      * tell NetBIOS Name Server that it may
                      * have given incorrect information
                      */

                     send NAME RELEASE REQUEST with name
                       and incorrect IP address to NetBIOS
                       Name Server;
                END
           END /* datagram error */

        END /* case */
   END

5.3.4.  PROTOCOLS FOR THE NBDD

   The key to NetBIOS Datagram forwarding service is the packet
   delivered to the destination end node must have the same NetBIOS
   header as if the source end node sent the packet directly to the
   destination end node.  Consequently, the NBDD does not reassemble
   NetBIOS Datagrams.  It forwards the UDP packet as is.
Top   ToC   RFC1002 - Page 81
   PROCEDURE  datagram_packet(packet)

   /*
    * processing initiated by a incoming datagram service
    * packet on a NBDD node.
    */

   BEGIN
        CASE packet type OF

           DATAGRAM SERVICE:
           BEGIN
                IF packet was sent as a directed
                   NetBIOS datagram THEN
                BEGIN
                  /*
                   * provide group forwarding service
                   *
                   * Forward datagram to each member of the
                   * group.  Can forward via:
                   *   1) get list of group members and send
                   *   the DATAGRAM SERVICE packet unicast
                   *   to each
                   *   2) use Group Multicast, if available
                   *   3) combination of 1) and 2)
                   */

                  ...

                END

                ELSE
                BEGIN
                  /*
                   * provide broadcast forwarding service
                   *
                   * Forward datagram to every node in the
                   * NetBIOS scope.  Can forward via:
                   *   1) get list of group members and send
                   *   the DATAGRAM SERVICE packet unicast
                   *   to each
                   *   2) use Group Multicast, if available
                   *   3) combination of 1) and 2)
                   */

                  ...

                END
           END /* datagram service */

           DATAGRAM ERROR:
Top   ToC   RFC1002 - Page 82
           BEGIN
             /*
              * Should never receive these because Datagrams
              * forwarded have source end node IP address and
              * port in NetBIOS header.
              */

             send DELETE NAME REQUEST with incorrect name and
                  IP address to NetBIOS Name Server;

           END /* datagram error */

           DATAGRAM QUERY REQUEST:
           BEGIN
             IF can send packet to DESTINATION_NAME THEN
             BEGIN
                  /*
                   * NBDD is able to relay Datagrams for
                   * this name
                   */

                  send POSITIVE DATAGRAM QUERY RESPONSE to
                    REQUEST source IP address and UDP port
                    with request's DGM_ID;
             END
             ELSE
             BEGIN
                  /*
                   * NBDD is NOT able to relay Datagrams for
                   * this name
                   */

                  send NEGATIVE DATAGRAM QUERY RESPONSE to
                    REQUEST source IP address and UDP port

                    with request's DGM_ID;
             END
           END /* datagram query request */

        END /* case */
   END /* procedure */
Top   ToC   RFC1002 - Page 83
6.  DEFINED CONSTANTS AND VARIABLES

   GENERAL:

      SCOPE_ID                   The name of the NetBIOS scope.

                                 This is expressed as a character
                                 string meeting the requirements of
                                 the domain name system and without
                                 a leading or trailing "dot".

                                 An implementation may elect to make
                                 this a single global value for the
                                 node or allow it to be specified
                                 with each separate NetBIOS name
                                 (thus permitting cross-scope
                                 references.)

      BROADCAST_ADDRESS          An IP address composed of the
                                 nodes's network and subnetwork
                                 numbers with all remaining bits set
                                 to one.

                                 I.e. "Specific subnet" broadcast
                                 addressing according to section 2.3
                                 of RFC 950.

      BCAST_REQ_RETRY_TIMEOUT    250 milliseconds.
                                 An adaptive timer may be used.

      BCAST_REQ_RETRY_COUNT      3

      UCAST_REQ_RETRY_TIMEOUT    5 seconds
                                 An adaptive timer may be used.

      UCAST_REQ_RETRY_COUNT      3

      MAX_DATAGRAM_LENGTH        576 bytes (default)



   NAME SERVICE:

      REFRESH_TIMER              Negotiated with NBNS for each name.

      CONFLICT_TIMER             1 second
                                 Implementations may chose a longer
                                 value.


      NAME_SERVICE_TCP_PORT      137 (decimal)
Top   ToC   RFC1002 - Page 84
      NAME_SERVICE_UDP_PORT      137 (decimal)

      INFINITE_TTL               0


   SESSION SERVICE:

      SSN_SRVC_TCP_PORT          139 (decimal)

      SSN_RETRY_COUNT            4 (default)
                                 Re-configurable by user.

      SSN_CLOSE_TIMEOUT          30 seconds (default)
                                 Re-configurable by user.

      SSN_KEEP_ALIVE_TIMEOUT     60 seconds, recommended, may be set to
                                 a higher value.
                                 (Session keep-alives are used only
                                 if configured.)

   DATAGRAM SERVICE:

      DGM_SRVC_UDP_PORT          138 (decimal)

      FRAGMENT_TO                2 seconds (default)
Top   ToC   RFC1002 - Page 85
REFERENCES



   [1]  "Protocol Standard For a NetBIOS Service on a TCP/UDP
        Transport: Concepts and Methods", RFC 1001, March 1987.

   [2]  J. Reynolds, J. Postel, "Assigned Numbers", RFC 990, November
        1986.

   [3]  P. Mockapetris, "Domain Names - Implementation and
        Specification", RFC 883, November 1983.