home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / pcrte224.zip / SOURCE.ZIP / PP.INC < prev    next >
Text File  |  1992-06-09  |  10KB  |  279 lines

  1. ;;******************************************************************************
  2. ;;                         point.inc      point.inc
  3. ;;******************************************************************************
  4. ;;
  5. ;;  Copyright (C) 1989 Vance Morrison
  6. ;;
  7. ;;
  8. ;; Permission to view, compile, and modify for LOCAL (intra-organization) 
  9. ;; USE ONLY is hereby granted, provided that this copyright and permission 
  10. ;; notice appear on all copies.  Any other use by permission only.
  11. ;;
  12. ;; Vance Morrison makes no representations about the suitability 
  13. ;; of this software for any purpose.  It is provided "as is" without expressed 
  14. ;; or implied warranty.  See the copywrite notice file for complete details.
  15. ;;
  16. ;;*****************************************************************************
  17. ;;
  18. ;;  point.asm contains the DL_IP interface for the point to point line 
  19. ;;  protocols.  This interface expects a serial IF interface and simply 
  20. ;;  converts it to a DL_IP interface (which really is quite easy).
  21. ;;
  22. ;;   PP_DECLARE name, serial_if, task
  23. ;;   PP_DEFINE name, ip_address, ip_mask
  24. ;;   PP_DL_IP_R_READ name, code_label
  25. ;;   PP_DL_IP_R_CONT_in_BX_CX_ES_const_BX_CX_DX_BP_SI_DI_ES name, ok
  26. ;;   PP_DL_IP_RETURN name
  27. ;;   PP_DL_IP_W_ACCESS_in_CX_out_DI_ES_const_CX_BP name, fail
  28. ;;   PP_DL_IP_W_WRITE_in_AX_CX_const_BP name, broadcast
  29. ;;   PP_DL_IP_IS_BROADCAST_in_BX_ES_const_AX_BX_CX_DX_BP_DI_ES name
  30. ;;   PP_DL_IP_COPY_in_CX_SI_DI_ES_out_SI_DI_const_BX_BP_ES name
  31. ;;
  32. ;;  Variables Provided by this module (READ ONLY!!!!)
  33. ;;
  34. ;;      pp_&name&_declared        1 if this object has been declared
  35. ;;      dl_ip_&name&_ip             the IP address
  36. ;;      dl_ip_&name&_mask           the network mask
  37. ;;      dl_ip_&name&_net            the network (IP addr bitwize AND ip_mask)
  38. ;;      dl_ip_&name&_broad          the network broadcast address
  39. ;;      dl_ip_&name&_flags          A word exclusively for IP use
  40. ;;      dl_ip_&name&_metric         The interface metric
  41. ;;      dl_ip_&name&_mtu            the Maximum transmission unit (packet size)
  42. ;;
  43. ;;*****************************************************************************
  44.  
  45.  
  46. ;;*****************************************************************************
  47. ;; PP_DECLARE name, serial_if, task
  48. ;;    PP_DECLARE declares the serial DL_IP object
  49. ;;
  50. PP_DECLARE MACRO name, serial_if, task
  51.     .errb <serial_if>
  52.     .errb <task>
  53.  
  54.     pp_&name&_declared = 1
  55.     pp_&name&_if = serial_if
  56.     pp_&name&_task = task
  57.  
  58.     dl_ip_&name&_mtu       = if_&serial_if&_mtu
  59.  
  60.     .DATA
  61.     global dl_ip_&name&_ip:dword
  62.     global dl_ip_&name&_mask:dword
  63.     global dl_ip_&name&_net:dword
  64.     global dl_ip_&name&_broad:dword
  65.     global dl_ip_&name&_flags:word
  66.     global dl_ip_&name&_metric:word
  67.  
  68.     global pp_&name&_read:word
  69.  
  70.     .CODE
  71.     global pp_&name&_continue:near
  72.     global pp_&name&_real_define:near
  73. ENDM
  74.  
  75.  
  76. ;;*****************************************************************************
  77. ;;   PP_DEFINE name, ip_address, ip_mask
  78. ;;      PP_DEFINE defines any memory and runs any initialization code.
  79. ;;
  80. PP_DEFINE MACRO name, ip_address, ip_mask
  81.  
  82. ifdef pp_&name&_declared
  83.     mov AX, word ptr ip_address                 ;; copy over params
  84.     mov BX, 0FFFFH                              ;; Force our assumtion
  85.     mov word ptr dl_ip_&name&_ip, AX
  86.     mov word ptr dl_ip_&name&_net, AX
  87.     mov word ptr dl_ip_&name&_broad, AX
  88.     mov word ptr dl_ip_&name&_mask, BX
  89.  
  90.     mov AX, word ptr ip_address+2
  91.     mov BX, word ptr ip_mask+2
  92.     mov word ptr dl_ip_&name&_ip+2, AX
  93.     mov word ptr dl_ip_&name&_mask+2, BX
  94.     and AX, BX
  95.     mov word ptr dl_ip_&name&_net+2, AX
  96.     not BX
  97.     or AX, BX
  98.     mov word ptr dl_ip_&name&_broad+2, AX
  99.  
  100.     call pp_&name&_real_define
  101. endif
  102. ENDM
  103.  
  104. PP_REAL_DEFINE MACRO name
  105.     local start, around
  106.  
  107. ifdef pp_&name&_declared
  108.     .DATA
  109.     dl_ip_&name&_ip         DD ?
  110.     dl_ip_&name&_mask       DD ?
  111.     dl_ip_&name&_net        DD ?
  112.     dl_ip_&name&_broad      DD ?
  113.     dl_ip_&name&_flags      DW ?
  114.     dl_ip_&name&_metric     DW ?
  115.  
  116.     pp_&name&_read dw ?                             ;; The code to call
  117.  
  118.     .CODE
  119.     jmp around
  120.         start:
  121.         PP_TASK name
  122.             ;; this does NOT fall through
  123.     around:
  124.  
  125.     pp_&name&_real_define:
  126.     mov pp_&name&_read, offset pp_&name&_continue
  127.     TASK_DEFINE %pp_&name&_task, start
  128.     RET
  129. endif
  130. ENDM
  131.  
  132.  
  133.  
  134. ;;******************************************************************************
  135. ;;   DL_IP_R_READ name, code_label
  136. ;;       DL_IP_R_READ declares that the code starting at 'code_label'
  137. ;;       should be called whenever a IP packet is read.  BX:ES is initilized
  138. ;;       to the begining of the IP packet before 'code_label' is called
  139. ;;       The code at 'code_label' should call PP_DL_IP_R_RETURN when it
  140. ;;       is done processing the packet.
  141. ;;       This procedure can only be called once per 'name'
  142. ;;
  143. PP_DL_IP_R_READ MACRO name, code_label
  144.     .errb <code_label>
  145.  
  146.     mov word ptr pp_&name&_read, offset code_label
  147. ENDM
  148.  
  149. ;;******************************************************************************
  150. ;;   DL_IP_R_CONT_in_BX_CX_ES name, ok
  151. ;;       DL_IP_R_CONT determines if the packet returned by R_READ in BX:ES
  152. ;;       of length CX is continuous.  If it is it jumps to 'ok' otherwise
  153. ;;       it just returns
  154. ;;
  155. PP_DL_IP_R_CONT_in_BX_CX_ES_const_BX_CX_DX_BP_SI_DI_ES MACRO name, ok
  156.     .errb <ok>
  157.  
  158.     jmp ok                      ;; it is always continuous
  159. ENDM
  160.  
  161. ;;******************************************************************************
  162. ;;   DL_IP_R_RETURN name
  163. ;;       DL_IP_R_RETURN should be executed by the READ routine to signal
  164. ;;       that it is done processing the packet.
  165. ;;
  166. PP_DL_IP_R_RETURN MACRO name
  167.     local done
  168.     .errb <name>
  169.  
  170.     jmp pp_&name&_continue
  171. ENDM
  172.  
  173.  
  174. ;;******************************************************************************
  175. ;;   DL_IP_IS_BROADCAST_in_BX_ES name
  176. ;;      DL_IP_IS_BROADCAST_in_BX_ES determines if the packet pointed to
  177. ;;      by BX:ES is a broadcast and sets the zero flag if it is NOT a
  178. ;;      broadcast
  179. ;;
  180. PP_DL_IP_IS_BROADCAST_in_BX_ES_const_AX_BX_CX_DX_BP_DI_ES MACRO name
  181.     .errb <name>
  182.     
  183.         ;; if the IP destination is on the local network AND it is
  184.         ;; not specifically for me, then I will consider it a broadcast.
  185.  
  186.         ;; this fakery is needed, because SLIP in particular does not
  187.         ;; have true DL addressing, it will read in ANY packet off the
  188.         ;; serial line, whether it is for 'me' (at a DL level) or not
  189.     mov SI, word ptr [BX+ip_dst+2]          ;; is it on my subnet
  190.     and SI, word ptr dl_ip_&name&_mask+2
  191.     cmp SI, word ptr dl_ip_&name&_net+2
  192.     jnz not_broad                           
  193.     mov SI, word ptr [BX+ip_dst]        
  194.     cmp SI, word ptr dl_ip_&name&_net
  195.     jnz not_broad
  196.         mov SI, word ptr [BX+ip_dst+2]      ;; and not me
  197.         cmp SI, word ptr dl_ip_&name&_ip+2
  198.         jnz done
  199.     not_broad:
  200.         cmp AX, AX
  201.     done:
  202.  
  203. ENDM
  204.  
  205.  
  206. ;;******************************************************************************
  207. ;;   DL_IP_W_ACCESS returns a pointer to an output buffer for a IP (network)
  208. ;;   packet.  The buffer is at least min(CX, dl_ip_mtu) bytes long.  The
  209. ;;   pointer is returned in DI.  If there is no buffer available
  210. ;;   this routine jumps to 'no_buffer'
  211. ;;
  212. PP_DL_IP_W_ACCESS_in_CX_out_DI_ES_const_CX_BP MACRO name, no_buffer
  213.     local fail, got_buffer
  214.     .errb <name>
  215.     .errb <no_buffer>
  216.  
  217.     IF_W_ACCESS_in_CX_out_DI_ES_const_BX_CX_BP %pp_&name&_if, no_buffer
  218. ENDM
  219.  
  220.  
  221. ;;******************************************************************************
  222. ;; DL_IP_W_WRITE_in_AX_CX name, broadcast
  223. ;;    DL_IP_W_WRITE actually signals the link layer to write a packet to the
  224. ;;    network.  The packet is assumed to be in the buffer returned by
  225. ;;    DL_IP_W_ACCESS.  CX is the length of the packet to send.   AX holds the
  226. ;;    last two bytes of the IP address to send the packet to.  (notice we are
  227. ;;    assuming a host portion of less than 16 bits).  if 'broadcast' is not
  228. ;;    blank, then the packet is written to the broadcast address.  AX is
  229. ;;    ignored in this case
  230. ;;
  231. PP_DL_IP_W_WRITE_in_AX_CX_const_BP MACRO name, broadcast 
  232.     local done, bad 
  233.     .errb <name> 
  234.  
  235.         ;; just send it out, we don't care about the address
  236.     IF_W_WRITE_in_CX_const_BX_BP_ES %pp_&name&_if 
  237. ENDM
  238.  
  239.  
  240. ;;******************************************************************************
  241. ;;   DL_IP_COPY_in_CX_SI_DI_ES_out_SI_DI name
  242. ;;      DL_IP_COPY_in_CX_SI_DI_ES copys a packet from the input buffer (pointed
  243. ;;      to by SI and the segment register given if IF_DECLARE) to an output
  244. ;;      buffer (pointed to by DI and dest_reg) of length CX.  It assumes the
  245. ;;      output buffer is contiguous.  (and the caller shouldn't care if the
  246. ;;      input buffer is contiguous)  COPY updates the pointers SI and DI
  247. ;;      to the end of the packet, and COPY could be called again if CX is not
  248. ;;      the total packet length (Note that CX MUST be even if you care about
  249. ;;      SI, and DI being updated properly)
  250. ;;
  251. PP_DL_IP_COPY_in_CX_SI_DI_ES_out_SI_DI_const_BX_BP_ES MACRO name
  252.     .errb <name>
  253.  
  254.     inc CX
  255.     shr CX, 1
  256.     rep
  257.     movsw
  258. ENDM
  259.  
  260.  
  261. ;;******************************************************************************
  262. ;;   PP_TASK is the read task that reads the next packet from the interface
  263. ;;   and dispatches it to the next higher protocol layer
  264. ;;
  265. PP_TASK MACRO name
  266.     local done
  267.     .errb <name>
  268.  
  269.     IF_R_ACCESS_out_BX_CX_ES %pp_&name&_if, done
  270.     jmp word ptr pp_&name&_read
  271.  
  272.     pp_&name&_continue:
  273.         IF_R_FREE_const_BX_CX_BP_SI_DI_ES %pp_&name&_if
  274.  
  275.     done:
  276.     TASK_RETURN %pp_&name&_task
  277. ENDM
  278.  
  279.