home *** CD-ROM | disk | FTP | other *** search
/ PC Press: Internet / PC_PRESS.ISO / software / dos / misc / inar-100.exe / SRC / PCROUTE / PP.INC < prev    next >
Encoding:
Text File  |  1995-05-21  |  10.1 KB  |  311 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_net, 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_BX_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
  38. ;;      dl_ip_&name&_broad          the network broadcast address
  39. ;;      dl_ip_&name&_gbroad         the global network broadcast address
  40. ;;      dl_ip_&name&_flags          A word exclusively for IP use
  41. ;;      dl_ip_&name&_metric         The interface metric
  42. ;;      dl_ip_&name&_id             The route id
  43. ;;      dl_ip_&name&_mtu            the Maximum transmission unit (packet size)
  44. ;;
  45. ;;*****************************************************************************
  46.  
  47.  
  48. ;;*****************************************************************************
  49. ;; PP_DECLARE name, serial_if, task
  50. ;;    PP_DECLARE declares the serial DL_IP object
  51. ;;
  52. PP_DECLARE MACRO name, serial_if, task
  53.     .errb <serial_if>
  54.     .errb <task>
  55.  
  56.     pp_&name&_declared = 1
  57.     pp_&name&_if = serial_if
  58.     pp_&name&_task = task
  59.  
  60.     dl_ip_&name&_mtu       = if_&serial_if&_mtu
  61.  
  62.     .DATA
  63.     global dl_ip_&name&_ip:dword
  64.     global dl_ip_&name&_mask:dword
  65.     global dl_ip_&name&_net:dword
  66.     global dl_ip_&name&_broad:dword
  67.     global dl_ip_&name&_gbroad:dword
  68.     global dl_ip_&name&_flags:word
  69.     global dl_ip_&name&_metric:word
  70.     global dl_ip_&name&_id:word
  71.  
  72.     global pp_&name&_read:word
  73.  
  74.     .CODE
  75.     global pp_&name&_continue:near
  76.     global pp_&name&_real_define:near
  77. ENDM
  78.  
  79.  
  80. ;;*****************************************************************************
  81. ;;   PP_DEFINE name, ip_address, ip_net, ip_mask
  82. ;;      PP_DEFINE defines any memory and runs any initialization code.
  83. ;;
  84. PP_DEFINE MACRO name, ip_address, ip_net, ip_mask
  85.     local class_A, class_B, class_C
  86.  
  87. ifdef pp_&name&_declared
  88.     mov AX, word ptr ip_address                 ;; copy over params
  89.     mov word ptr dl_ip_&name&_ip, AX
  90.     mov AX, word ptr ip_address+2
  91.     mov word ptr dl_ip_&name&_ip+2, AX
  92.  
  93.     mov AX, word ptr ip_net
  94.     mov BX, word ptr ip_mask
  95.     mov word ptr dl_ip_&name&_net, AX
  96.     mov word ptr dl_ip_&name&_mask, BX
  97.  
  98.     not BX
  99.     or AX, BX
  100.     mov word ptr dl_ip_&name&_broad, AX
  101.  
  102.     mov AX, word ptr ip_net+2
  103.     mov BX, word ptr ip_mask+2
  104.     mov word ptr dl_ip_&name&_net+2, AX
  105.     mov word ptr dl_ip_&name&_mask+2, BX
  106.  
  107.     mov DL, AL
  108.     mov DH, 0ffh
  109.     not BX
  110.     or AX, BX
  111.     mov word ptr dl_ip_&name&_broad+2, AX
  112.  
  113.     mov AX, word ptr ip_net
  114.     test AL, 80h
  115.     jz class_A
  116.     test AL, 40h
  117.     jz class_B
  118.     jmp class_C
  119.     class_A:
  120.         mov AH, DH
  121.     class_B:
  122.         mov DL, DH
  123.     class_C:
  124.     mov word ptr dl_ip_&name&_gbroad, AX
  125.     mov word ptr dl_ip_&name&_gbroad+2, DX
  126.  
  127.     call pp_&name&_real_define
  128. endif
  129. ENDM
  130.  
  131. PP_REAL_DEFINE MACRO name
  132.     local start, around
  133.  
  134. ifdef pp_&name&_declared
  135.     .DATA
  136.     dl_ip_&name&_ip         DD ?
  137.     dl_ip_&name&_mask       DD ?
  138.     dl_ip_&name&_net        DD ?
  139.     dl_ip_&name&_broad      DD ?
  140.     dl_ip_&name&_gbroad     DD ?
  141.     dl_ip_&name&_flags      DW ?
  142.     dl_ip_&name&_metric     DW ?
  143.     dl_ip_&name&_id         DW ?
  144.  
  145.     pp_&name&_read dw ?                             ;; The code to call
  146.  
  147.     .CODE
  148.     jmp around
  149.         start:
  150.         PP_TASK name
  151.             ;; this does NOT fall through
  152.     around:
  153.  
  154.     pp_&name&_real_define:
  155.     mov pp_&name&_read, offset pp_&name&_continue
  156.     TASK_DEFINE %pp_&name&_task, start
  157.     RET
  158. endif
  159. ENDM
  160.  
  161.  
  162.  
  163. ;;******************************************************************************
  164. ;;   DL_IP_R_READ name, code_label
  165. ;;       DL_IP_R_READ declares that the code starting at 'code_label'
  166. ;;       should be called whenever a IP packet is read.  BX:ES is initilized
  167. ;;       to the begining of the IP packet before 'code_label' is called
  168. ;;       The code at 'code_label' should call PP_DL_IP_R_RETURN when it
  169. ;;       is done processing the packet.
  170. ;;       This procedure can only be called once per 'name'
  171. ;;
  172. PP_DL_IP_R_READ MACRO name, code_label
  173.     .errb <code_label>
  174.  
  175.     mov word ptr pp_&name&_read, offset code_label
  176. ENDM
  177.  
  178. ;;******************************************************************************
  179. ;;   DL_IP_R_CONT_in_BX_CX_ES name, ok
  180. ;;       DL_IP_R_CONT determines if the packet returned by R_READ in BX:ES
  181. ;;       of length CX is continuous.  If it is it jumps to 'ok' otherwise
  182. ;;       it just returns
  183. ;;
  184. PP_DL_IP_R_CONT_in_BX_CX_ES_const_BX_CX_DX_BP_SI_DI_ES MACRO name, ok
  185.     .errb <ok>
  186.  
  187.     jmp ok                      ;; it is always continuous
  188. ENDM
  189.  
  190. ;;******************************************************************************
  191. ;;   DL_IP_R_RETURN name
  192. ;;       DL_IP_R_RETURN should be executed by the READ routine to signal
  193. ;;       that it is done processing the packet.
  194. ;;
  195. PP_DL_IP_R_RETURN MACRO name
  196.     local done
  197.     .errb <name>
  198.  
  199.     jmp pp_&name&_continue
  200. ENDM
  201.  
  202.  
  203. ;;******************************************************************************
  204. ;;   DL_IP_IS_BROADCAST_in_BX_ES name
  205. ;;      DL_IP_IS_BROADCAST_in_BX_ES determines if the packet pointed to
  206. ;;      by BX:ES is a broadcast and sets the zero flag if it is NOT a
  207. ;;      broadcast
  208. ;;
  209. PP_DL_IP_IS_BROADCAST_in_BX_ES_const_AX_BX_CX_DX_BP_DI_ES MACRO name
  210.     .errb <name>
  211.     
  212.         ;; if the IP destination is on the local network AND it is
  213.         ;; not specifically for me, then I will consider it a broadcast.
  214.  
  215.         ;; this fakery is needed, because SLIP in particular does not
  216.         ;; have true DL addressing, it will read in ANY packet off the
  217.         ;; serial line, whether it is for 'me' (at a DL level) or not
  218.     mov SI, word ptr ES:[BX+ip_dst+2]          ;; is it on my subnet
  219.     and SI, word ptr dl_ip_&name&_mask+2
  220.     cmp SI, word ptr dl_ip_&name&_net+2
  221.     jnz not_broad                           
  222.     mov SI, word ptr ES:[BX+ip_dst]        
  223.     and SI, word ptr dl_ip_&name&_mask
  224.     cmp SI, word ptr dl_ip_&name&_net
  225.     jnz not_broad
  226.         mov SI, word ptr ES:[BX+ip_dst]        ;; and not me
  227.         cmp SI, word ptr dl_ip_&name&_ip
  228.         jnz done
  229.         mov SI, word ptr ES:[BX+ip_dst+2]
  230.         cmp SI, word ptr dl_ip_&name&_ip+2
  231.         jnz done
  232.     not_broad:
  233.         cmp AX, AX
  234.     done:
  235.  
  236. ENDM
  237.  
  238.  
  239. ;;******************************************************************************
  240. ;;   DL_IP_W_ACCESS returns a pointer to an output buffer for a IP (network)
  241. ;;   packet.  The buffer is at least min(CX, dl_ip_mtu) bytes long.  The
  242. ;;   pointer is returned in DI.  If there is no buffer available
  243. ;;   this routine jumps to 'no_buffer'
  244. ;;
  245. PP_DL_IP_W_ACCESS_in_CX_out_DI_ES_const_CX_BP MACRO name, no_buffer
  246.     local fail, got_buffer
  247.     .errb <name>
  248.     .errb <no_buffer>
  249.  
  250.     IF_W_ACCESS_in_CX_out_DI_ES_const_BX_CX_BP %pp_&name&_if, no_buffer
  251. ENDM
  252.  
  253.  
  254. ;;******************************************************************************
  255. ;; DL_IP_W_WRITE_in_AX_BX_CX name, broadcast
  256. ;;    DL_IP_W_WRITE actually signals the link layer to write a packet to the
  257. ;;    network.  The packet is assumed to be in the buffer returned by
  258. ;;    DL_IP_W_ACCESS.  CX is the length of the packet to send.
  259. ;;    AX:BX holds the IP address to send the packet to. if 'broadcast' is not
  260. ;;    blank, then the packet is written to the broadcast address.  AX:BX is
  261. ;;    ignored in this case
  262. ;;
  263. PP_DL_IP_W_WRITE_in_AX_BX_CX_const_BP MACRO name, broadcast 
  264.     local done, bad 
  265.     .errb <name> 
  266.  
  267.         ;; just send it out, we don't care about the address
  268.     IF_W_WRITE_in_CX_const_BX_BP_ES %pp_&name&_if 
  269. ENDM
  270.  
  271.  
  272. ;;******************************************************************************
  273. ;;   DL_IP_COPY_in_CX_SI_DI_ES_out_SI_DI name
  274. ;;      DL_IP_COPY_in_CX_SI_DI_ES copys a packet from the input buffer (pointed
  275. ;;      to by SI and the segment register given if IF_DECLARE) to an output
  276. ;;      buffer (pointed to by DI and dest_reg) of length CX.  It assumes the
  277. ;;      output buffer is contiguous.  (and the caller shouldn't care if the
  278. ;;      input buffer is contiguous)  COPY updates the pointers SI and DI
  279. ;;      to the end of the packet, and COPY could be called again if CX is not
  280. ;;      the total packet length (Note that CX MUST be even if you care about
  281. ;;      SI, and DI being updated properly)
  282. ;;
  283. PP_DL_IP_COPY_in_CX_SI_DI_ES_out_SI_DI_const_BX_BP_ES MACRO name
  284.     .errb <name>
  285.  
  286.     inc CX
  287.     shr CX, 1
  288.     rep
  289.     movsw
  290. ENDM
  291.  
  292.  
  293. ;;******************************************************************************
  294. ;;   PP_TASK is the read task that reads the next packet from the interface
  295. ;;   and dispatches it to the next higher protocol layer
  296. ;;
  297. PP_TASK MACRO name
  298.     local done
  299.     .errb <name>
  300.  
  301.     IF_R_ACCESS_out_BX_CX_ES %pp_&name&_if, done
  302.     jmp word ptr pp_&name&_read
  303.  
  304.     pp_&name&_continue:
  305.         IF_R_FREE_const_BX_CX_BP_SI_DI_ES %pp_&name&_if
  306.  
  307.     done:
  308.     TASK_RETURN %pp_&name&_task
  309. ENDM
  310.  
  311.