home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / PCMCIA / CLDFM / STGY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  10.7 KB  |  340 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /**************************************************************************
  13.  *
  14.  * SOURCE FILE NAME = STGY.C
  15.  *
  16.  * DESCRIPTIVE NAME =
  17.  *
  18.  *
  19.  * VERSION =
  20.  *
  21.  * DATE
  22.  *
  23.  * DESCRIPTION This file contains the device driver entry point
  24.  *             and strategy routine
  25.  *
  26.  * FUNCTIONS
  27.  *
  28.  * ENTRY POINTS:
  29.  *
  30.  * DEPENDENCIES:
  31.  *
  32.  * NOTES
  33.  *
  34.  *
  35.  * STRUCTURES
  36.  *
  37.  * EXTERNAL REFERENCES
  38.  *
  39.  * EXTERNAL FUNCTIONS
  40.  *
  41. */
  42.  
  43. #include "types.h"
  44. #include "cs.h"
  45. #include "cs_idc.h"
  46. #include "com_idc.h"
  47. #include "devhlp.h"
  48. #include "config.h"
  49. #include "shell.h"
  50.  
  51.  
  52. #define DEV_ATTRIB 0x8180              /* 1000 0001 1000 0000         */
  53.                  /*
  54.                  ** 15 = 1    character device
  55.                  ** 14 = 0    offset to idc entry point is not set
  56.                  ** 13 = 0    for block device driver use only
  57.                  ** 12 = 0    not shared device
  58.                  ** 11 = 0    open / close is not required
  59.                  ** 10 = 0    reserved
  60.                  **  9 - 7 = 011   enable capabilities bit strip
  61.                  **  4 - 6    reserved
  62.                  **  3 = 0     not clock device
  63.                  **  2 = 0     not null device
  64.                  **  1 = 0     not stdout device
  65.                  **  0 = 0     not stdin device
  66.                  */
  67.  
  68. #define DEV_CAPS 0x00000010
  69.  
  70.  
  71. #define CMD_INIT 0x00                  /* comand for device initialization */
  72. #define CMD_INIT_COMP 0x1f
  73.  
  74. #define RPDONE 0x0100                  /* return successful                */
  75. #define RPERR 0x8000                   /* return error                     */
  76. #define RPGENFAIL 0x000c               /* return error: General failure    */
  77.  
  78. #define MAX_ARG_LEN 25
  79. #define MAX_ARG_NUM 3
  80.  
  81.    /*
  82.    ** type definitons
  83.    */
  84. typedef struct dev_hdr {               /* template for device header       */
  85.    ULONG next;                         /* next driver in chain             */
  86.    USHORT attrib;                      /* attribute                        */
  87.    void near *strategy;                /* address of strategy routine      */
  88.    void near *idc;                     /* address of IDC routine           */
  89.    UCHAR name[16];                     /* 8 char device driver name        */
  90.    ULONG capablities;                  /*     and 8 bytes reserved         */
  91. } DEVHDR;
  92.  
  93. typedef struct req_packet {            /* template for request header      */
  94.    UCHAR length;                       /* request packet length            */
  95.    UCHAR unit;                         /* unit code for block DD only      */
  96.    UCHAR command;                      /* command code                     */
  97.    USHORT status;                      /* return status                    */
  98.    UCHAR reserved[4];                  /* reserved bytes                   */
  99.    ULONG qlink;                        /* queue linkage                    */
  100.    union {                             /* command-specific data            */
  101.       struct {
  102.          UCHAR dummy1;
  103.          ULONG devhlp_entry;           /* dev help address                 */
  104.          ULONG argP;                   /* argument pointer                 */
  105.          UCHAR dummy3;
  106.       } init_in;
  107.       struct {
  108.          UCHAR dummy1;
  109.          USHORT code_end;              /* final code offset                */
  110.          USHORT data_end;              /* final data offset                */
  111.          ULONG dummy2;
  112.          UCHAR dummy3;
  113.       } init_out;
  114.       struct {
  115.          UCHAR category;               /* category code                    */
  116.          UCHAR function;               /* function code                    */
  117.          void far *param_bufP;         /* pointer to parameters            */
  118.          void far *data_bufP;          /* pointer to data                  */
  119.       } ioctl;
  120.    } s;
  121. } REQPACKET;
  122.  
  123.    /*
  124.    ** private function prototypes
  125.    */
  126. void get_parameters(ULONG argP, short *argc, char **argv);
  127.  
  128.    /*
  129.    ** private global variable declarations
  130.    */
  131. DEVHDR dev_hdr = {0xffffffff,            /* link                           */
  132.                  DEV_ATTRIB,             /* attribute                      */
  133.                  (void near *) strategy, /* &Strategy routine              */
  134.                  (void near *) 0,        /* &IDC routine for stream Handler*/
  135.                  "ESTDFM$         ",     /* 8 bytes name and               */
  136.                  DEV_CAPS                /*           8 bytes reserved     */
  137. };
  138.  
  139. static BOOL Installed = 0;               /* flag for driver installed status */
  140.  
  141. static char oco_notice[8][40] = {
  142.                               "Licensed Material - Property of IBM",
  143.                               "                                   ",
  144.                               "(C) Copyright IBM Corp. 1992,",
  145.                               "All Rights Reserved.",
  146.                               "U.S. Government Users Restricted Rights",
  147.                               "- Use, duplication or disclosure",
  148.                               "restricted by GSA ADP Schedule Contract",
  149.                               "with IBM Corp."};
  150.  
  151. char   Arg[MAX_ARG_NUM][MAX_ARG_LEN];
  152. short  Argc;
  153. char   *Argv[MAX_ARG_NUM];
  154.  
  155.    /*
  156.    ** external global variable declarations
  157.    */
  158. extern USHORT End_of_data;               /* end of data marker             */
  159.  
  160.  
  161. /****************************************************************************
  162.  *
  163.  * FUNCTION NAME = do_start
  164.  *
  165.  * DESCRIPTION   = This function is the device driver strategy routine.
  166.  *                 The parameter 'rpP' is a pointer to a block of information
  167.  *                 from the operating system called the request packet.
  168.  *
  169.  * INPUT         =
  170.  *
  171.  * OUTPUT        =
  172.  *
  173.  * RETURN-NORMAL =
  174.  *
  175.  * RETURN-ERROR  =
  176.  *
  177.  ****************************************************************************/
  178.  
  179. void do_strat(REQPACKET far *rpP)
  180. {
  181.     USHORT num_of_sockets, i;
  182.  
  183.         /* initialization event
  184.         */
  185.     switch(rpP->command)
  186.     {
  187.       case CMD_INIT:
  188.  
  189.                 /* error if driver already installed
  190.                 */
  191.             if (Installed)
  192.             {
  193.                 rpP->status = RPDONE | RPERR | RPGENFAIL;
  194.                 rpP->s.init_out.code_end = 0;
  195.                 rpP->s.init_out.data_end = 0;
  196.                 return;
  197.             }
  198.  
  199.                 /* initialize operating system device helper access
  200.                 */
  201.             devhlp_init(rpP->s.init_in.devhlp_entry);
  202.  
  203.                 /* establish idc with card services driver
  204.                 */
  205.             if (cs_idc_init() == -1)
  206.             {
  207.                 rpP->status = RPDONE | RPERR | RPGENFAIL;
  208.                 rpP->s.init_out.code_end = 0;
  209.                 rpP->s.init_out.data_end = 0;
  210.                 return;
  211.             }
  212.  
  213.                 /* establish idc with com driver
  214.                 */
  215.             if (com_idc_init() == -1)
  216.             {
  217.                 rpP->status = RPDONE | RPERR | RPGENFAIL;
  218.                 rpP->s.init_out.code_end = 0;
  219.                 rpP->s.init_out.data_end = 0;
  220.                 return;
  221.             }
  222.  
  223.                 /* process and store the arguments
  224.                 */
  225.             for (i = 0; i <= MAX_ARG_NUM - 1; i++)
  226.                 Argv[i] = &Arg[i][0];
  227.             get_parameters(rpP->s.init_in.argP, &Argc, (char**) Argv);
  228.  
  229.                 /* driver has successfully installed
  230.                 */
  231.             rpP->status == RPDONE;
  232.             rpP->s.init_out.code_end = (USHORT) end_of_text;
  233.             rpP->s.init_out.data_end = (USHORT) &End_of_data;
  234.             Installed = 1;
  235.             return;
  236.  
  237.       case CMD_INIT_COMP:
  238.  
  239.                 /* check for card services
  240.                 */
  241.             if (!cs_services_present())
  242.             {
  243.                 rpP->status = RPDONE | RPERR | RPGENFAIL;
  244.                 return;
  245.             }
  246.  
  247.                 /* get number of sockets and store configuration info
  248.                 */
  249.             num_of_sockets = cs_get_num_of_sockets();
  250.             if (store_config_info(Argc, Argv, num_of_sockets) != 0)
  251.             {
  252.                 rpP->status = RPDONE | RPERR | RPGENFAIL;
  253.                 return;
  254.             }
  255.                 /* register with card services
  256.                 */
  257.             if (cs_register_client() != 0)
  258.             {
  259.                 rpP->status = RPDONE | RPERR | RPGENFAIL;
  260.                 return;
  261.             }
  262.  
  263.                 /* everythings successful
  264.                 */
  265.             rpP->status = RPDONE;
  266.             return;
  267.     }
  268. }
  269.  
  270.  
  271. /****************************************************************************
  272.  *
  273.  * FUNCTION NAME = get_parameters
  274.  *
  275.  * DESCRIPTION   =
  276.  *
  277.  * INPUT         =
  278.  *
  279.  * OUTPUT        =
  280.  *
  281.  * RETURN-NORMAL =
  282.  *
  283.  * RETURN-ERROR  =
  284.  *
  285.  ****************************************************************************/
  286.  
  287.  
  288. static void get_parameters(ULONG argP, short *argc, char **argv)
  289. {
  290.     char far *strP;
  291.     USHORT i, j;
  292.  
  293.     i = 0;
  294.     j = 0;
  295.     *argc = 0;
  296.  
  297.     strP = (char far *) argP;
  298.  
  299.     while (1)
  300.     {
  301.         if (j > MAX_ARG_LEN - 2)
  302.         {
  303.             argv[i][j] = '\0';
  304.             (*argc)++;
  305.             i++;
  306.             j = 0;
  307.             while ((*strP != ' ') && (*strP != '\0'))
  308.                 strP++;
  309.             while (*strP == ' ')
  310.                 strP++;
  311.             if (*strP == '\0')
  312.                 return;
  313.         }
  314.  
  315.         if (i > MAX_ARG_NUM - 1)
  316.             return;
  317.  
  318.         if (*strP == ' ')
  319.         {
  320.             argv[i][j] = '\0';
  321.             (*argc)++;
  322.             i++;
  323.             j = 0;
  324.             while (*strP == ' ')
  325.                 strP++;
  326.             if (*strP == '\0')
  327.                 return;
  328.         }
  329.  
  330.         if (*strP == '\0')
  331.         {
  332.             argv[i][j] = '\0';
  333.             (*argc)++;
  334.             return;
  335.         }
  336.  
  337.         argv[i][j++] = *strP++;
  338.     }
  339. }
  340.