home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IE3802.ZIP / IEEE8022 / DLCINTF.H < prev    next >
Text File  |  1991-12-12  |  16KB  |  437 lines

  1. /*******************************************************************************
  2. *   Module name :    DLCINTF                                                   *
  3. *                                                                              *
  4. *   Function :       Lan adapter 802.2 interface functions                     *
  5. *                                                                              *
  6. *   Routines in                                                                *
  7. *   this module:     dlc_open_sap        (ccb_parm,adapternum,sap)             *
  8. *                    dlc_open_station    (ccb_parm,adapternum,sapid,destaddr)  *
  9. *                    dlc_reset           (ccb_parm,adapternum,stationid)       *
  10. *                    dlc_transmit_I_fram (ccb_parm,adapternum,buffer1,bufflen1,*
  11. *                                         buffer2,bufflen2,stationid)          *
  12. *                    dlc_connect_station (ccb_parm,adapternum,stationid,       *
  13. *                                         route_info)                          *
  14. *                    dlc_status_read     (ccb_parm,adapternum,stationid)       *
  15. *                                                                              *
  16. * Parameters:                                                                  *
  17. *                                                                              *
  18. *         Input:     The adapter number. Other parms are supplied as necessary.*
  19. *                                                                              *
  20. *        Output:     Return code is based upon the kind of CCB executed.       *
  21. *                    If the return code is 0xFF then the CCB is one that       *
  22. *                    does not make the program wait while it runs, so the      *
  23. *                    CCB command is valid, but incomplete when it returns.     *
  24. *                    The return code for a successful "no-wait" CCB is zero.   *
  25. *                    Otherwise the return code from the CCB is returned,       *
  26. *                    indicating that an error was detected.                    *
  27. *                                                                              *
  28. *   OS/2 Required:    Extended Edition 1.1 or higher.                          *
  29. *                                                                              *
  30. *******************************************************************************/
  31.  
  32.  
  33. /*-------------------------------------------------------------------+
  34. │ dlc_open_sap                                                       │
  35. │                 Activate a SAP and reserve a number of link        │
  36. │                 stations for the SAP.                              │
  37. │                                                                    │
  38. +-------------------------------------------------------------------*/
  39.  
  40. byte dlc_open_sap (ccb_parm,adapternum,sap,sem,wait)
  41. struct ccb_pt *ccb_parm;
  42. byte adapternum;
  43. byte  sap;
  44. #ifdef E32TO16
  45. HSYSSEM _Seg16 sem;
  46. #else
  47. HSYSSEM sem;
  48. #endif
  49. BOOL wait;
  50. {
  51.         struct command_control_block_dlr *ccbptr;
  52.         struct dlc_open_sap_parms *pt;
  53.         static byte sap_bpool[4096];
  54.  
  55.         ccbptr = &ccb_parm->ccb;
  56.         pt     = &ccb_parm->pt.open_sap;
  57.  
  58.         memset(ccbptr,0,sizeof(struct command_control_block_dlr));
  59.         memset(pt,0,sizeof(struct dlc_open_sap_parms));
  60.  
  61.         ccbptr->ccb_command     = LLC_DLC_OPEN_SAP;
  62.         ccbptr->ccb_adapter     = adapternum;
  63. #ifdef E32TO16
  64.         ccbptr->parm_1.ccb_parm_offset = (address)pt;
  65. #else
  66.         ccbptr->parm_1.parm.off_12.ccb_parm_offset = FP_OFF (pt);
  67. #endif
  68.         ccbptr->ccb_pointer     = ZEROADDRESS;
  69.         ccbptr->ccb_retcode     = 0xff;
  70.         ccbptr->ccb_appl_key    = ApplKey;
  71.         ccbptr->ccb_appl_id     = ApplId;
  72. #ifdef E32TO16
  73.         ccbptr->ccb_semaphore   = sem;
  74. #else
  75.         ccbptr->ccb_semaphore   = (dword)sem;
  76. #endif
  77.  
  78.         pt->sap_value         = sap;
  79.         pt->sap_station_count = 2;
  80.         pt->options_priority  = 0x0C;
  81.         pt->dlc_pool_address  = (address) sap_bpool;
  82.         pt->dlc_pool_len      = 256;
  83.         pt->status.dlc_status_flag   = (address)(0x0001);
  84.  
  85.         if(sem)
  86.           DosSemSet(sem);
  87.         pass_ccb (ccbptr);
  88.  
  89.         if(wait)
  90.           {
  91.           if(sem)
  92.             DosSemWait(sem,-1L);
  93.           else
  94.             while (ccbptr->ccb_retcode == 0xff);
  95.           }
  96.         return ccbptr->ccb_retcode;
  97. }
  98.  
  99.  
  100. /*-------------------------------------------------------------------+
  101. │ dlc_open_station                                                   │
  102. │                 Allocate resources for a link station.  The adapter│
  103. │                 support interface performs functions to set up the │
  104. │                 the link station in the adapter, but no ring       │
  105. │                 communications takes place.  A dlc_connect_station │
  106. │                 command must be issued either to the local or      │
  107. │                 remote link station by its application program to  │
  108. │                 initiate ring communications. Thereafter, another  │
  109. │                 dlc_connect_station must be issued at the other    │
  110. │                 station to complete the establishment of the link. │
  111. │                                                                    │
  112. +-------------------------------------------------------------------*/
  113.  
  114. byte dlc_open_station (ccb_parm,adapternum,sapid,destaddr,destsap,sem,wait)
  115. struct ccb_pt *ccb_parm;
  116. byte adapternum;
  117. word sapid,destsap;
  118. byte destaddr[];
  119. #ifdef E32TO16
  120. HSYSSEM _Seg16 sem;
  121. #else
  122. HSYSSEM sem;
  123. #endif
  124. BOOL wait;
  125. {
  126.         struct command_control_block_dlr *ccbptr;
  127.         struct dlc_open_station_parms *pt;
  128.  
  129.         ccbptr = &ccb_parm->ccb;
  130.         pt     = &ccb_parm->pt.open_station;
  131.  
  132.         memset(ccbptr,0,sizeof(struct command_control_block_dlr));
  133.         memset(pt,0,sizeof(struct dlc_open_station_parms));
  134.  
  135.         ccbptr->ccb_command     = LLC_DLC_OPEN_STATION;
  136.         ccbptr->ccb_adapter     = adapternum;
  137. #ifdef E32TO16
  138.         ccbptr->parm_1.ccb_parm_offset = (address)pt;
  139. #else
  140.         ccbptr->parm_1.parm.off_12.ccb_parm_offset = FP_OFF (pt);
  141. #endif
  142.         ccbptr->ccb_pointer     = ZEROADDRESS;
  143.         ccbptr->ccb_retcode     = 0xff;
  144.         ccbptr->ccb_appl_key    = ApplKey;
  145.         ccbptr->ccb_appl_id     = ApplId;
  146. #ifdef E32TO16
  147.         ccbptr->ccb_semaphore   = sem;
  148. #else
  149.         ccbptr->ccb_semaphore   = (dword)sem;
  150. #endif
  151.  
  152.         pt->station_id         = sapid;
  153.         pt->rsap_value         = destsap;
  154. #ifdef E32TO16
  155.         pt->destination_offset =  (address)destaddr;
  156. #else
  157.         pt->destination_offset = FP_OFF (destaddr);
  158. #endif
  159.  
  160.         if(sem)
  161.           DosSemSet(sem);
  162.  
  163.         pass_ccb (ccbptr);
  164.  
  165.         if(wait)
  166.           {
  167.           if(sem)
  168.             DosSemWait(sem,-1L);
  169.           else
  170.             while (ccbptr->ccb_retcode == 0xff);
  171.           }
  172.         return ccbptr->ccb_retcode;
  173. }
  174.  
  175.  
  176. /*-------------------------------------------------------------------+
  177. │ dlc_connect_station                                                │
  178. │                 Start or complete a SABME-UA exchange to place     │
  179. │                 both the local and remote link stations in a data  │
  180. │                 transfer state.  This will be the first time ring  │
  181. │                 activity takes place between two devices.          │
  182. │                                                                    │
  183. +-------------------------------------------------------------------*/
  184.  
  185. byte dlc_connect_station (ccb_parm,adapternum,stationid,route_info,sem,wait)
  186. struct ccb_pt *ccb_parm;
  187. byte adapternum;
  188. word stationid;
  189. byte *route_info[];
  190. #ifdef E32TO16
  191. HSYSSEM _Seg16 sem;
  192. #else
  193. HSYSSEM sem;
  194. #endif
  195. BOOL wait;
  196. {
  197.         struct command_control_block_dlr *ccbptr;
  198.         struct dlc_connect_station_parms *pt;
  199.  
  200.         ccbptr = &ccb_parm->ccb;
  201.         pt     = &ccb_parm->pt.connect;
  202.  
  203.         memset(ccbptr,0,sizeof(struct command_control_block_dlr));
  204.         memset(pt,0,sizeof(struct dlc_connect_station_parms));
  205.  
  206.         ccbptr->ccb_command     = LLC_DLC_CONNECT_STATION;
  207.         ccbptr->ccb_adapter     = adapternum;
  208. #ifdef E32TO16
  209.         ccbptr->parm_1.ccb_parm_offset = (address)pt;
  210. #else
  211.         ccbptr->parm_1.parm.off_12.ccb_parm_offset = FP_OFF (pt);
  212. #endif
  213.         ccbptr->ccb_pointer     = ZEROADDRESS;
  214.         ccbptr->ccb_retcode     = 0xff;
  215.         ccbptr->ccb_appl_key    = ApplKey;
  216.         ccbptr->ccb_appl_id     = ApplId;
  217. #ifdef E32TO16
  218.         ccbptr->ccb_semaphore   = sem;
  219. #else
  220.         ccbptr->ccb_semaphore   = (dword)sem;
  221. #endif
  222.  
  223.         pt->station_id = stationid;
  224. #ifdef E32TO16
  225.         pt->routing_offset  = (address)route_info;
  226. #else
  227.         pt->routing_offset  = FP_OFF (route_info);
  228. #endif
  229.  
  230.         if(sem)
  231.           DosSemSet(sem);
  232.         pass_ccb (ccbptr);
  233.         if(wait)
  234.           {
  235.           if(sem)
  236.             DosSemWait(sem,-1L);
  237.           else
  238.             while (ccbptr->ccb_retcode == 0xff);
  239.           }
  240.         return ccbptr->ccb_retcode;
  241. }
  242.  
  243.  
  244. /*-------------------------------------------------------------------+
  245. │ dlc_reset                                                          │
  246. │                 Resets either one SAP and all associated link      │
  247. │                 stations or all SAPs and all associated link       │
  248. │                 stations.  All outstanding commands will be        │
  249. │                 terminated for the SAP(s) and station(s).  All     │
  250. │                 communications will cease and all the related      │
  251. │                 resources will be released.  They must be reopened │
  252. │                 to be used again.                                  │
  253. │                                                                    │
  254. │                 A stationid of 0x0000 defines all SAPs & stations, │
  255. │                 and a stationid of 0xnn00 defines SAP 'nn' and all │
  256. │                 its stations.                                      │
  257. │                                                                    │
  258. +-------------------------------------------------------------------*/
  259.  
  260. byte dlc_reset (ccb_parm,adapternum,stationid,sem,wait)
  261. struct ccb_pt *ccb_parm;
  262. byte adapternum;
  263. word  stationid;
  264. #ifdef E32TO16
  265. HSYSSEM _Seg16 sem;
  266. #else
  267. HSYSSEM sem;
  268. #endif
  269. BOOL wait;
  270. {
  271.         struct command_control_block_dlr *ccbptr;
  272.  
  273.         ccbptr = &ccb_parm->ccb;
  274.         memset(ccbptr,0,sizeof(struct command_control_block_dlr));
  275.  
  276.         ccbptr->ccb_command   = LLC_DLC_RESET;
  277.         ccbptr->ccb_adapter   = adapternum;
  278.         ccbptr->ccb_pointer   = ZEROADDRESS;
  279.         ccbptr->ccb_retcode   = 0xff;
  280.         ccbptr->parm_1.parm.off_12.station_id    = stationid;
  281.         if (stationid == 0x0000)
  282.            ccbptr->parm_1.parm.off_14.reset_all_saps = 0x01;
  283.         ccbptr->parm_2.system_key    = SystemKey;
  284.         ccbptr->ccb_appl_key  = ApplKey;
  285.         ccbptr->ccb_appl_id   = ApplId;
  286. #ifdef E32TO16
  287.         ccbptr->ccb_semaphore   = sem;
  288. #else
  289.         ccbptr->ccb_semaphore   = (dword)sem;
  290. #endif
  291.  
  292.         if(sem)
  293.           DosSemSet(sem);
  294.         pass_ccb (ccbptr);
  295.         if(wait)
  296.           {
  297.           if(sem)
  298.           {
  299.             DosSemWait(sem,-1L);
  300.           }
  301.           else
  302.             while (ccbptr->ccb_retcode == 0xff);
  303.           }
  304.         return ccbptr->ccb_retcode;
  305. }
  306.  
  307. /*-------------------------------------------------------------------+
  308. │ dlc_transmit_I_frame                                               │
  309. │                 Transmits "information" data for a link station.   │
  310. │                 The adapter provides the LAN and DLC headers. Only │
  311. │                 actual data is provided by the caller.  The max    │
  312. │                 length of the data is 2042 bytes.                  │
  313. │                                                                    │
  314. +-------------------------------------------------------------------*/
  315.  
  316. byte dlc_transmit_I_frame (ccb_parm,adapternum,buffer1,bufflen1,buffer2,bufflen2,stationid,destsap,sem,wait)
  317. struct ccb_pt *ccb_parm;
  318. byte adapternum;
  319. BUFFER *buffer1;
  320. word bufflen1;
  321. BUFFER *buffer2;
  322. word bufflen2;
  323. word stationid,destsap;
  324. #ifdef E32TO16
  325. HSYSSEM _Seg16 sem;
  326. #else
  327. HSYSSEM sem;
  328. #endif
  329. BOOL wait;
  330. {
  331.         struct command_control_block_dlr *ccbptr;
  332.         struct transmit_parms *pt;
  333.  
  334.         ccbptr = &ccb_parm->ccb;
  335.         pt     = &ccb_parm->pt.transmit;
  336.  
  337.         memset(ccbptr,0,sizeof(struct command_control_block_dlr));
  338.         ccbptr->ccb_command     = LLC_TRANSMIT_I_FRAME;
  339.         ccbptr->ccb_retcode     = 0xff;
  340.         ccbptr->ccb_adapter     = adapternum;
  341. #ifdef E32TO16
  342.         ccbptr->parm_1.ccb_parm_offset = (address)pt;
  343. #else
  344.         ccbptr->parm_1.parm.off_12.ccb_parm_offset = FP_OFF (pt);
  345. #endif
  346.         ccbptr->ccb_pointer     = ZEROADDRESS;
  347.         ccbptr->ccb_appl_key    = ApplKey;
  348.         ccbptr->ccb_appl_id     = ApplId;
  349. #ifdef E32TO16
  350.         ccbptr->ccb_semaphore   = sem;
  351. #else
  352.         ccbptr->ccb_semaphore   = (dword)sem;
  353. #endif
  354.  
  355.         memset(pt,0,sizeof(struct transmit_parms));
  356.  
  357.         pt->station_id     = stationid;
  358.         pt->rsap           = destsap;
  359.         pt->buffer_len_one = bufflen1;
  360.         pt->buffer_len_two = bufflen2;
  361.         pt->buffer_one     = (address) buffer1;
  362.         pt->buffer_two     = (address) buffer2;
  363.  
  364.         if(sem)
  365.           DosSemSet(sem);
  366.         pass_ccb (ccbptr);
  367.         if(wait)
  368.           {
  369.           if(sem)
  370.             DosSemWait(sem,-1L);
  371.           else
  372.             while (ccbptr->ccb_retcode == 0xff);
  373.           }
  374.         return ccbptr->ccb_retcode;
  375. }
  376.  
  377. /****************************************************************************
  378. * dlc_status_read                                                           *
  379. *    This function issues a dlc.read command to wait for dlc status change. *
  380. *                                                                           *
  381. *****************************************************************************/
  382.  
  383. byte dlc_status_read ( ccb_parm,adapternum, stationid ,sem,wait)
  384. struct ccb_pt *ccb_parm;
  385. byte adapternum;
  386. word stationid;
  387. #ifdef E32TO16
  388. HSYSSEM _Seg16 sem;
  389. #else
  390. HSYSSEM sem;
  391. #endif
  392. BOOL wait;
  393.  
  394. {
  395.         struct command_control_block_dlr *ccbptr;
  396.         struct read_pt_status *pt;
  397.  
  398.         ccbptr = &ccb_parm->ccb;
  399.         pt     = &ccb_parm->pt.read;
  400.         memset(ccbptr,0,sizeof(struct command_control_block_dlr));
  401.  
  402.         ccbptr->ccb_command     = LLC_READ;
  403.         ccbptr->ccb_retcode     = 0xff;
  404.         ccbptr->ccb_adapter     = adapternum;
  405. #ifdef E32TO16
  406.         ccbptr->parm_1.ccb_parm_offset = (address)pt;
  407. #else
  408.         ccbptr->parm_1.parm.off_12.ccb_parm_offset = FP_OFF (pt);
  409. #endif
  410.         ccbptr->ccb_pointer     = ZEROADDRESS;
  411.         ccbptr->ccb_appl_key    = ApplKey;
  412.         ccbptr->ccb_appl_id     = ApplId;
  413. #ifdef E32TO16
  414.         ccbptr->ccb_semaphore   = sem;
  415. #else
  416.         ccbptr->ccb_semaphore   = (dword)sem;
  417. #endif
  418.  
  419.         memset(pt,0,sizeof(struct read_pt_status));
  420.  
  421.         pt->station_id = stationid;
  422.         pt->option_idicator = READ_SAP;
  423.         pt->event_set = LLC_DLC_STATUS_CHANGE;
  424.  
  425.         if(sem)
  426.           DosSemSet(sem);
  427.         pass_ccb (ccbptr);
  428.         if(wait)
  429.           {
  430.           if(sem)
  431.             DosSemWait(sem,-1L);
  432.           else
  433.             while (ccbptr->ccb_retcode == 0xff);
  434.           }
  435.         return ccbptr->ccb_retcode;
  436. }
  437.