home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n12 / plgnplay.exe / TELEPATH.C < prev    next >
C/C++ Source or Header  |  1995-12-01  |  4KB  |  148 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //      TELEPATH.C: Example device driver
  4. //
  5. ///////////////////////////////////////////////////////////////////////////////
  6.  
  7. #define WANTVXDWRAPS
  8. #include <basedef.h>
  9. #include <vmm.h>
  10. #include <debug.h>
  11. #include <vmmreg.h>
  12. #include <vxdwraps.h>
  13. #include <configmg.h>
  14. #include <regstr.h>
  15.  
  16. static BYTE irq;            // allocated IRQ
  17.  
  18. CONFIGRET OnConfigure(CONFIGFUNC cf, SUBCONFIGFUNC scf,
  19.     DEVNODE devnode, DWORD refdata, ULONG flags);
  20.  
  21. BOOL OnSysDynamicDeviceInit()
  22.     {                            // OnSysDynamicDeviceInit
  23.     return TRUE;
  24.     }                            // OnSysDynamicDeviceInit
  25.  
  26. BOOL OnSysDynamicDeviceExit()
  27.     {                            // OnSysDynamicDeviceExit
  28.     return TRUE;
  29.     }                            // OnSysDynamicDeviceExit
  30.  
  31. CONFIGRET OnPnpNewDevnode(DEVNODE devnode, DWORD loadtype)
  32.     {                            // OnPnpNewDevnode
  33.     switch (loadtype)
  34.         {                        // select function to perform
  35.  
  36.     case DLVXD_LOAD_DEVLOADER:        // loadtype == 2
  37.         return CM_Register_Device_Driver(devnode, OnConfigure, 0,
  38.             (CM_REGISTER_DEVICE_DRIVER_REMOVABLE
  39.             | CM_REGISTER_DEVICE_DRIVER_DISABLEABLE));
  40.         }                        // select function to perform
  41.  
  42.     return CR_DEFAULT;
  43.     }                            // OnPnpNewDevnode
  44.  
  45. CONFIGRET OnConfigure(CONFIGFUNC cf, SUBCONFIGFUNC scf,
  46.     DEVNODE devnode, DWORD refdata, ULONG flags)
  47.     {                            // OnConfigure
  48.  
  49. #ifdef DEBUG
  50.     char id[MAX_DEVICE_ID_LEN];
  51.     DEBUG_CONFIG_NAMES
  52.     char *subfunc = "";
  53.     static char *substart[] = {"DYNAMIC_START", "FIRST_START"};
  54.     static char *substop[] = {"DYNAMIC_STOP", "HAS_PROBLEM"};
  55.     static char *subremove[] = {"DYNAMIC", "SHUTDOWN", "REBOOT"};
  56.     static char *subtest[] = {"CAN_STOP", "CAN_REMOVE"};
  57.     static char *subapm[] = {"TEST_STANDBY", "TEST_SUSPEND",
  58.         "TEST_STANDBY_FAILED", "TEST_SUSPEND_FAILED",
  59.         "TEST_STANDBY_SUCCEEDED", "TEST_SUSPEND_SUCCEEDED",
  60.         "RESUME_STANDBY", "RESUME_SUSPEND", "RESUME_CRITICAL",
  61.         "UI_ALLOWED"};
  62.  
  63.     switch (cf)
  64.         {                        // get subfunction name
  65.     case CONFIG_START:
  66.         subfunc = substart[scf];
  67.         break;
  68.     case CONFIG_STOP:
  69.         subfunc = substop[scf];
  70.         break;
  71.     case CONFIG_REMOVE:
  72.         subfunc = subremove[scf];
  73.         break;
  74.     case CONFIG_TEST:
  75.         subfunc = subtest[scf];
  76.         break;
  77.     case CONFIG_APM:
  78.         subfunc = subapm[scf];
  79.         break;
  80.         }                        // get subfunction name
  81.  
  82.     CM_Get_Device_ID(devnode, id, sizeof(id), 0);
  83.     if (cf < NUM_CONFIG_COMMANDS)
  84.         Debug_Printf("TELEPATH DRIVER: %s(%s), %s\r\n", lpszConfigName[cf], subfunc, id);
  85.     else
  86.         Debug_Printf("TELEPATH DRIVER: %X(%X), %s\r\n", cf, scf, id);
  87. #endif
  88.  
  89.     switch (cf)
  90.         {                        // select on function code
  91.  
  92.     case CONFIG_START:            // cf == 1
  93.         {                        // CONFIG_START
  94.         
  95.         // This is the normal way to obtain a configuration that
  96.         // only includes the standard resources:
  97.         
  98.         CMCONFIG config;
  99.         CM_Get_Alloc_Log_Conf(&config, devnode,
  100.             CM_GET_ALLOC_LOG_CONF_ALLOC);
  101.         irq = config.bIRQRegisters[0];
  102.  
  103.         // This is how to get a configuration that includes a
  104.         // private resource:
  105.  
  106.         {
  107.         #define ResType_Telepath ((0x10 << 5) | 5)
  108.  
  109.         typedef struct
  110.             {                            // telepath resource description
  111.             ULONG allocated;            // mask for allocated channel
  112.             ULONG requested;            // mask for requested channels
  113.             } TELEPATH_RESOURCE;        // telepath resource description
  114.  
  115.         LOG_CONF logconf;
  116.         RES_DES hres;
  117.         #define pres ((TELEPATH_RESOURCE*) hres)
  118.  
  119.         CM_Get_First_Log_Conf(&logconf, devnode, ALLOC_LOG_CONF);
  120.         if (CM_Get_Next_Res_Des(&hres, (RES_DES) logconf,
  121.             ResType_Telepath, NULL, 0) == CR_SUCCESS)
  122.             {                        // has telepath channel
  123.             // do something with pres->allocated
  124.             }                        // has telepath channel
  125.  
  126.         #undef pres
  127.         }
  128.  
  129.         // Here we would initialize the device, doing things
  130.         // like VPICD_Virtualize_IRQ, etc.
  131.  
  132.         return CR_SUCCESS;
  133.         }                        // CONFIG_START
  134.  
  135.     case CONFIG_REMOVE:            // cf == 4
  136.     case CONFIG_STOP:            // cf == 2
  137.         
  138.         // Here we would disable the device and do things
  139.         // like unvirtualizing our IRQ
  140.         
  141.         irq = 255;
  142.         return CR_SUCCESS;
  143.  
  144.     default:
  145.         return CR_DEFAULT;
  146.         }                        // select on function code
  147.     }                            // OnConfigure
  148.