Establishing Sessions

When two computers initiate a session using NBF, there is an exchange of LSNs.

Initially a frame is sent from the originating computer with an LSN of 0. LSN 0 is a reserved LSN used for the FindName frame of the NameQuery frame.

Figure 16.5 shows this session-creation frame exchange.


Figure 16.5 Multicast of NameQuery

All computers read the frame and check to see if they have the name in their console tree and if there is a LISTEN NCB frame pending on the name. If there is a LISTEN NCB pending, the computer assigns a new LSN for itself. It adds the LSN to the response frame, satisfying the LISTEN NCB, which now contains just the LSN used on that computer. The LSNs used by individual computers might be different. They do not have to match, but each computer always uses the same LSN for a particular session. This number is assigned when a program issues a call for a network control block (NCB). Even though each computer knows the LSN of the other, the information is not used. The more important information for the two communicating partners is the network adapter addresses that are part of the frames. As the frames are exchanged, each partner picks up the address of the other in the source address component of the frame received. The NBF protocol keeps the network adapter address of the remote partner so that subsequent frames can be addressed directly.



This process applies only to NBF connections. NetBIOS connections established by using NetBIOS over TCP/IP (NetBT) are handled differently.

For information about NetBIOS over TCP/IP, see "Introduction to TCP/IP" and "Windows 2000 TCP/IP" in the TCP/IP Core Networking Guide .

Windows 2000 has to use the same NameQuery frame to establish connections with remote computers using NBF. The NameQuery frame transmitted must contain the 1-byte-wide LSN to be used.

For example, suppose a computer running Windows 2000 Server and NBF assigns a session number of 1 to identify the session between itself and computer A and also assigns the number 1 for the simultaneous session with computer B. The computer running Windows 2000 Server can identify the different sessions because it uses the computer network adapter address as part of the TDI handle to further identify each session. When the computer running Windows 2000 Server sends a session frame to either computer A or computer B, it uses the network adapter address to direct the frame across the network. Therefore, computer A does not receive the frames addressed to computer B, and vice versa. However, if the computer running Windows 2000 Server and NBF establishes another session with computer A, it must use a session number other than 1 to uniquely identify the second session.

The NameQuery frame from Windows 2000 contains the LSN associated with the TDI handle that satisfies either the NCB CALL or the LISTEN NCB. In the case of an NCB CALL, it is not multicast but is addressed directly to the remote computer.

The Local Session Number (LSN) from the NBF matrix cannot be the one returned to the process issuing the NCB CALL or LISTEN NCB commands. NBF might have established connections with multiple remote computers with LSN=5, for example. Windows 2000 must return an LSN that uniquely defines its session.

As stated earlier, NBF uses the TDI handle to determine to which LSN and network address to send frames, and each process has its own set of LSNs available to it. Therefore, a component called Netbios.sys is used between the originating process and the TDI interface of NBF to translate a process ID and an LSN into a TDI handle.

Figure 16.6 illustrates an NCB CALL processed through the NetBIOS and NBF matrices. The Netbios.sys matrix has 254 LSNs per LAN adapter number per process. In Windows 2000, the LAN adapter number identifies a unique binding of a protocol driver and one network adapter driver. Each process can have up to 254 sessions per LAN adapter number, not just a total of 254 sessions.

Figure 16.6 shows how the NCB CALL is processed through the NetBIOS and NBF matrices.


Figure 16.6 NCB Call Processed Through the NetBIOS and NBF Matrices

Netbios.sys builds a matrix that has LSNs down the side, process IDs along the top, and TDI handles in the cells. It is the LSN from this table that is passed back to the originating process.

To further understand how Netbios.sys uses this matrix, suppose a process needs to establish a session with a remote computer. Before the process can issue the CALL NCB, it must issue a Reset NCB frame. This command signals Netbios.sys to allocate space in its TDI handle table, among other things. When the Reset NCB is satisfied, the process issues a CALL NCB to make a connection with a specific remote computer. This NCB is directed down to the Netbios.sys device driver. The driver opens a new TDI handle to NBF and sends the command to NBF.

NBF issues the first NameQuery with LSN=0 to find the remote computer. When the remote computer responds, the network adapter address is extracted from the frame, and a column in the NBF table is created. The second NameQuery with an LSN is sent directly to the remote computer. When that frame is returned successfully, NBF returns a successful status code from the TDI call to the Netbios.sys driver.

Netbios.sys then fills in the LSN from its table into the NCB and sends it back to the calling process.