;---------------------------------------------------------------------------; ; RS-232 Data Switch Firmware ; ; ; ; File: CALL.ASM ; ; ; ; This file contains code relevant to setting up and clearing connections ; ; ("calls") through the switch. ; ;---------------------------------------------------------------------------; calls segment code unit rseg calls $nolist $include(globals.asm) $list extrn code(skipspc) extrn code(prtstr) extrn code(getport) extrn code(prompt) extrn code(vconnect) extrn code(setown) extrn code(bye) extrn code(checknorm) extrn code(checkmaint) extrn code(putchar) extrn code(printhex2) extrn code(inc_str) public call_cmd public link_cmd public unlink_cmd public clear_cmd public off_cmd public maskaddr public clear public isconnected public isnotmine public getmaskbit ;--------------------------------------------------------------------------- ; Function: call_cmd ; ; Description: ; This function performs the processing for the "call" command. It gets ; a port number from the command line, then sets up a bidirectional ; connection to it. First, it verifies that access to the port can be ; allowed, and clears any previous connection to another port. ; ; Command syntax: CALL ; ; Inputs: Port number (from command line) ; Outputs: None ; ; Get destination port number from command line. call_cmd: lcall skipspc jnz call_ok mov dptr,#inc_str lcall prtstr call_exit: ljmp prompt call_ok: lcall getport jz call_exit mov r6,a ; Check if allowed to access this port, if in restricted mode. ; Print an error message and exit, if not. jnb restrictflag,not_rest mov r0,a mov a,myport lcall getmaskbit jc not_rest mov dptr,#notauthmsg lcall prtstr ljmp prompt ; Check if someone else has a connection to this port already. ; If so, indicate that the port is busy and exit. not_rest: mov a,r6 lcall isconnected jz c_port_ok mov a,r6 mov r0,myport lcall isnotmine jz c_port_ok mov dptr,#d_busy_str lcall prtstr ljmp prompt ; Disconnect anything currently listening to the ; originating port (clears any previous call) c_port_ok: mov r5,#1 clear_loop: mov dptr,#c_sourcetbl-1 mov a,r5 movc a,@a+dptr cjne a,myport,cl_loopend mov a,r5 mov r0,myport lcall isnotmine jnz cl_loopend ; Found a port belonging to, and listening to the originator. mov r0,5 mov r1,#15 lcall vconnect cl_loopend: inc r5 cjne r5,#maxport+1,clear_loop ; Establish bidirectional link, establish ownership of both ; ends of the link, and go online. mov r0,myport mov r1,6 lcall vconnect mov r0,6 mov r1,myport lcall vconnect mov a,myport lcall setown mov a,r6 lcall setown ljmp bye d_busy_str: db 'Destination port busy.',13,10,0 notauthmsg: db 'Not authorized to access destination port.',13,10,0 ;--------------------------------------------------------------------------- ; Function: clear ; ; Description: ; This function clears all connections which have been set up by a given ; port. ; ; Inputs: R6 - port number ; Outputs: None ; ; Scan all ports. clear: mov r5,#1 clr_loop: mov a,r5 ; Check if current connection has a connection belonging to ; the port in question. lcall isconnected jz clr_loopend mov a,r5 mov r0,6 lcall isnotmine jnz clr_loopend ; If it does, disconnect it. mov r0,5 mov r1,#15 lcall vconnect clr_loopend: inc r5 cjne r5,#maxport+1,clr_loop ret ;--------------------------------------------------------------------------- ; Functions: clear_cmd, off_cmd ; ; Description: ; These functions perform processing for the "clear" and "off" commands. ; Both clear all connections belonging to the command port. "clear" ; remains in command mode, whereas "off" drops out of command mode. ; ; Command syntax: CLEAR ; OFF ; ; Inputs: None ; Outputs: None ; clear_cmd: mov r6,myport lcall clear ljmp prompt off_cmd: mov r6,myport lcall clear ljmp bye ;--------------------------------------------------------------------------- ; Function: isconnected ; ; Description: ; This function finds if a port is connected to anything. ; ; Inputs: A - port number ; Outputs: A - Zero: Not connected ; Nonzero: Connected ; isconnected: mov dptr,#c_sourcetbl-1 movc a,@a+dptr clr c subb a,#15 ret ;--------------------------------------------------------------------------- ; Function: isnotmine ; ; Description: ; This function finds if the connection on a given port belongs to the ; port whose number is given in R0. ; ; Inputs: A - port number of connection ; R0 - port number of owner ; Outputs: A - Zero: Owned ; Nonzero: Not owned ; isnotmine: mov dptr,#c_owntbl-1 movc a,@a+dptr clr c subb a,r0 ret ;--------------------------------------------------------------------------- ; Function: link_cmd ; ; Description: ; This function performs the processing for the "link" command. It gets ; two port numbers from the command line, and sets up a link from the ; second one to the first one. First, it verifies that nobody else is ; using the destination port, and that the user has sufficient access ; privilege. ; ; Command syntax: LINK ; ; Inputs: Port numbers (from command line) ; Outputs: None ; ; Make sure the user is not in restricted mode. link_cmd: lcall checknorm jnz link_exit ; Get two port numbers and exit with an error if not successful. lcall skipspc jz link_incomp lcall getport jz link_exit mov r5,a lcall skipspc jz link_incomp lcall getport jz link_exit mov r6,a ; Check that it's OK to send to the destination port. mov a,r5 lcall isconnected jz dest_ok mov r0,myport mov a,r5 lcall isnotmine jnz dest_not_ok ; Set up the connection. dest_ok: mov r0,5 mov r1,6 lcall vconnect mov a,r5 lcall setown link_exit: ljmp prompt ; Error exits dest_not_ok: mov dptr,#d_busy_str sjmp link_err link_incomp: mov dptr,#inc_str link_err: lcall prtstr ljmp prompt ;--------------------------------------------------------------------------- ; Function: unlink_cmd ; ; Description: ; This function performs the processing for the "unlink" command. It gets ; a port number from the command line, and clears the link to this port, ; if any. The link must either be owned by the current user, or the ; current user must be at the "maintenance" access level. ; ; Command syntax: UNLINK ; ; Inputs: Port number (from command line) ; Outputs: None ; ; Get the port number. unlink_cmd: lcall skipspc jz link_incomp lcall getport jz link_exit mov r5,a lcall isconnected jz notconn ; Skip ownership check if in maintenance mode. jb maintflag,unlink_ok mov a,r5 mov r0,myport lcall isnotmine jnz notowned ; Clear the connection. unlink_ok: mov r0,5 mov r1,#15 lcall vconnect ljmp prompt ; Error exits. notconn: mov dptr,#nc_str sjmp link_err notowned: mov dptr,#notown_str sjmp link_err nc_str: db 'Port is not connected.',13,10,0 notown_str: db 'Permission denied.' db 13,10,0 ;--------------------------------------------------------------------------- ; Function: maskaddr ; ; Description: ; This function computes the address of the call permission mask for a ; given port. ; ; Inputs: A - port number ; Outputs: DPTR - address of (16-bit) mask ; maskaddr: dec a mov b,#2 mul ab add a,#masktbl-256*(masktbl/256) mov dpl,a clr a addc a,#masktbl/256 mov dph,a ret ;--------------------------------------------------------------------------- ; Function: getmaskbit ; ; Description: ; This function gets the specified bit from the call permission mask of ; a specified port. ; ; Inputs: A - port number ; R0 - mask bit (destination port) number ; Outputs: C - mask bit value. 0: Not OK to connect ; 1: OK to connect ; getmaskbit: lcall maskaddr mov a,r0 dec a jb acc.3,notlow inc dptr notlow: clr acc.3 inc a mov r0,a movx a,@dptr xloop: rrc a djnz r0,xloop ret end