home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bootp.zip / BOOTP1.ASM < prev    next >
Assembly Source File  |  1992-02-05  |  6KB  |  402 lines

  1.     include    masmdefs.hsm
  2.     include model.hsm
  3.  
  4. screen        macro spot
  5.         push    ax                ;SCREEN
  6.         push    ds                ;SCREEN
  7.         mov    ax, 0B800h            ;SCREEN
  8.         mov    ds, ax                ;SCREEN
  9.         db    0FEh                ;inc byte ptr []
  10.         db    06h
  11.         dw    &spot&*2            ;SCREEN
  12.         pop    ds                ;SCREEN
  13.         pop    ax                ;SCREEN
  14.         endm
  15.  
  16. codedef BOOTP1
  17. datadef
  18.  
  19.     public    _oldpack
  20.     public    _end_wpack
  21.     public    _your_ip
  22.     public    _server_ip
  23.     public    _gateway_ip
  24.     public    _server_hw
  25.     public    _vendor
  26.  
  27. cstart  BOOTP1
  28. cproc   newpack
  29.  
  30.     jmp    around
  31.     db    "PKT DRVR"
  32.     db    0
  33.     db    "BOOTP by Bruce Campbell"
  34.     db    0
  35. handle    label    word
  36.     dw    0
  37. upcall:
  38.     db    09Ah
  39. upoff    label    word
  40.     dw    0
  41. upseg    label    word
  42.     dw    0
  43.     ret
  44.  
  45. _your_ip    label    word
  46.     dw    0
  47. _your_ip2    label    word
  48.     dw    0
  49. _server_ip    label    word
  50.     dw    0
  51. _server_ip2    label    word
  52.     dw    0
  53. _gateway_ip    label    word
  54.     dw    0
  55. _gateway_ip2    label    word
  56.     dw    0
  57.  
  58. _server_hw    label    word
  59.     dw    0
  60. _server_hw2    label    word
  61.     dw    0
  62. _vendor        label    word
  63.     db    60 dup(0)
  64.  
  65. around:
  66.     sti
  67.     cmp    ah, 2                ;access
  68.     jnz    not_acc
  69. ;
  70. ;    access        DS:SI points to access type
  71. ;            CX is length of access flag
  72. ;            ES:DI points to upcall
  73. ;
  74. ;    carry clear on success, AX = handle
  75. ;
  76.     cmp    cx, 2
  77.     jnz    do_old2
  78.     push    ax
  79.     mov    ax,[si]
  80.     cmp    ax,0008            ;ip packet ?
  81.     pop    ax
  82.     jnz    do_old2
  83.     push    di
  84.     push    es
  85.     call    callpkt            ;do the access
  86.     pop    es
  87.     pop    di
  88.     jc    doneboot2        ;it failed
  89.     mov    cs:handle,ax
  90.     mov    cs:upoff,di
  91.     mov    cs:upseg,es
  92. doneboot2:
  93.     jmp    doneboot
  94. do_old2:
  95.     jmp    do_old
  96. not_acc:
  97.     cmp    ah, 3                ;release
  98.     jnz    not_rel
  99. ;
  100. ;    release        BX is handle to release
  101. ;
  102.     cmp    bx,cs:handle            ;does it match ?
  103.     jnz    do_old3
  104.     call    callpkt                ;do the release
  105.     jc    doneboot3            ;it failed
  106.     mov    cs:handle,0
  107.     mov    cs:upoff,0
  108.     mov    cs:upseg,0
  109. doneboot3:
  110.     jmp    doneboot
  111. do_old3:
  112.     jmp    do_old
  113. not_bp:
  114.     pop    ax
  115.     jmp    do_old
  116. not_rel:
  117.     cmp    ah, 4                ;transmit
  118.     jnz    do_old3
  119. ;
  120. ;    transmit        DS:SI len CX is packet
  121. ;
  122.     cmp    cx,342                ;a bootp is 342 bytes
  123.     jnz    do_old3
  124.     push    ax
  125.     mov    ax,[si+12]            ;get type
  126.     cmp    ax,0008                ;bootp has IP type
  127.     jnz    not_bp1
  128.     mov    ax,[si]
  129.     cmp    ax,0FFFFh
  130.     jnz    not_bp1
  131.     mov    ax,[si+2]
  132.     cmp    ax,0FFFFh
  133.     jnz    not_bp1
  134.     mov    ax,[si+4]
  135.     cmp    ax,0FFFFh
  136.     jnz    not_bp1
  137.     mov    ax,[si+34]
  138.     cmp    ax,4400h            ;bootp client
  139.     jnz    not_bp1
  140.     mov    ax,[si+36]            ;bootp server
  141.     cmp    ax,4300h
  142.     jnz    not_bp1
  143.     mov    al,[si+42]            ;bootp operation
  144.     cmp    al,1
  145. not_bp1:
  146.     jnz    not_bp
  147.     mov    ax,cs:upoff
  148.     or    ax,cs:upseg
  149.     jz    not_bp                ;no upcall set yet
  150.     pop    ax
  151.     push    si
  152.     push    ds
  153.     call    callpkt
  154.     pop    ds
  155.     pop    si
  156.     jnc    tranworked
  157.     jmp    doneboot
  158. tranworked:
  159.     pushf
  160.     push    ax
  161.     push    bx
  162.     push    cx
  163.     push    dx
  164.     push    di
  165.     push    si
  166.     push    bp
  167.     push    ds
  168.     push    es
  169.  
  170.     mov    ax,0        ;allocate
  171.     mov    bx,cs:handle
  172.     mov    cx,342
  173.  
  174.     push    si
  175.     push    ds
  176.     call    upcall
  177.     pop    ds
  178.     pop    si
  179.  
  180.     mov    ax,es
  181.     or    ax,di
  182.     jnz    okbuf
  183.     jmp    nobuf
  184.  
  185. okbuf:
  186.     push    di
  187.     mov    cx,342
  188.     cld
  189.     rep    movsb
  190.     pop    di
  191.  
  192.     mov    ax,es
  193.     mov    ds,ax
  194.     mov    si,di
  195.  
  196.     mov    byte ptr [si+42],2    ;bootp reply
  197.  
  198.     mov    ax,[si+6]
  199.     mov    [si+0],ax
  200.     mov    ax,[si+8]
  201.     mov    [si+2],ax
  202.     mov    ax,[si+10]
  203.     mov    [si+4],ax
  204.  
  205.     mov    ax,0
  206.     mov    [si+6],ax
  207.     mov    ax,cs:_server_hw
  208.     mov    [si+8],ax
  209.     mov    ax,cs:_server_hw2
  210.     mov    [si+10],ax
  211.  
  212.     mov    ax,[si+54]
  213.     mov    [si+30],ax
  214.     mov    ax,[si+56]
  215.     mov    [si+32],ax
  216.  
  217.     mov    ax,[si+54]
  218.     or    ax,[si+56]        ;does client know IP address ?
  219.     jnz    ip_known
  220.  
  221.     mov    ax,cs:_your_ip
  222.     mov    [si+58],ax
  223.     mov    [si+30],ax
  224.     mov    ax,cs:_your_ip2
  225.     mov    [si+60],ax
  226.     mov    [si+32],ax
  227.  
  228. ip_known:
  229.  
  230.     mov    ax,cs:_server_ip
  231.     mov    [si+62],ax
  232.     mov    [si+26],ax
  233.     mov    ax,cs:_server_ip2
  234.     mov    [si+64],ax
  235.     mov    [si+28],ax
  236.  
  237.     mov    ax,cs:_gateway_ip
  238.     mov    [si+66],ax
  239.     mov    ax,cs:_gateway_ip2
  240.     mov    [si+68],ax
  241.  
  242.     mov    word ptr [si+34],04300h
  243.     mov    word ptr [si+36],04400h
  244.  
  245.     mov    word ptr [si+40],0        ;udp checksum
  246.     mov    word ptr [si+24],0        ;ip checksum
  247.  
  248.     mov    ax,[si+278]            ;get the magic thing
  249.     cmp    ax,08263h
  250.     jnz    no_magic
  251.     mov    ax,[si+280]            ;get the magic thing
  252.     cmp    ax,06353h
  253.     jnz    no_magic
  254.  
  255.     push    si
  256.     push    ds
  257.  
  258.     push    ds
  259.     pop    es
  260.  
  261.     mov    di,si
  262.     add    di,282
  263.  
  264.     push    cs
  265.     pop    ds
  266.  
  267.     mov    cx,60
  268.     mov    si,offset _vendor
  269.  
  270.     cld
  271.     rep    movsb
  272.  
  273.     pop    ds
  274.     pop    si
  275.  
  276.     push    si
  277.     add    si, 14
  278.     mov    cx, 20
  279.     call    _inchksum
  280.     pop    si
  281.  
  282.     not    AX
  283.     mov    word ptr [si+24],AX        ;ip checksum
  284.  
  285. no_magic:
  286.     mov    ax,1        ;process
  287.     mov    bx,cs:handle
  288.     mov    cx,342
  289.  
  290.     call    upcall
  291.  
  292. nobuf:
  293.  
  294.     pop    es
  295.     pop    ds
  296.     pop    bp
  297.     pop    si
  298.     pop    di
  299.     pop    dx
  300.     pop    cx
  301.     pop    bx
  302.     pop    ax
  303.     popf
  304.     jmp    doneboot
  305. do_old:
  306.     call    callpkt
  307. doneboot:
  308.     db    0CAh,02,00            ;retf 2
  309.  
  310. callpkt:
  311.     pushf
  312.     db    09Ah
  313. _oldpack    label    dword
  314.     dd    0    
  315.     ret
  316.  
  317. cendp   newpack
  318.  
  319. cproc    inchksum
  320.  
  321.         mov     BL, CL
  322.  
  323.         shr     CX, 1                   ; group into words
  324.         xor     DX, DX                  ; set checksum to 0
  325.         cld
  326.         clc
  327.  
  328. deloop: lodsw
  329.         adc     DX, AX
  330.         loop    deloop
  331.  
  332.         adc     DX, 0                   ; only two necessary
  333.         adc     DX, 0
  334.  
  335. remain: and     BL, 1
  336.         jz      done
  337.  
  338.         xor     AH, AH
  339.         lodsb
  340.         add     DX, AX
  341.         adc     DX, 0
  342.         adc     DX, 0
  343.  
  344. done:   mov     AX,DX           ; result into ax
  345.     ret
  346.  
  347. cendp   inchksum
  348.  
  349.  
  350. cproc    endwww
  351. _end_wpack    label    word
  352.     dw    offset    _end_wpack
  353. cendp    endwww
  354.  
  355. cpublic bopen
  356.  
  357.     mov    DX,+@AB+0[BP]
  358.     mov    AX,03D00h
  359.     int    21h
  360.     jnc    b_ok
  361.     mov    ax,0FFFFh
  362. b_ok:
  363.  
  364. creturn bopen
  365.  
  366. lbuf    label    byte
  367.     dd    0
  368.  
  369. cpublic    bread
  370.  
  371.     push    DS
  372.     mov    BX,+@AB+0[BP]
  373.     mov    CX,1
  374.     push    CS
  375.     pop    DS
  376.     mov    DX,offset lbuf
  377.     mov    AX,03F00h
  378.     int    21h
  379.     jc    r_fail
  380.     cmp    ax,1
  381.     jnz    r_fail
  382.     mov    al,cs:lbuf
  383.     jmp    r_ok
  384. r_fail:
  385.     mov    ax,0FFFFh
  386. r_ok:
  387.     pop    DS
  388.  
  389. creturn    bread
  390.  
  391. cpublic    bclose
  392.  
  393.     mov    BX,+@AB+0[BP]
  394.     mov    AX,03E00h
  395.     int    21h
  396.  
  397. creturn    bclose
  398.  
  399. cend    BOOTP1
  400.  
  401.     end
  402.