Folks-

I'm just learning all about the many cool OID ioctl's that can be used to communicate with device drivers - OS independently (as I understand). The latest one I came across is OID_PNP_QUERY_POWER, which directs the device driver to: "Tell me what power state you are currently at".

Windows XP identifies that the responses from using OID_PNP_QUERY_POWER should be one of:

0x0 NdisDeviceStateUnspecified (PM not supported) 0x1 NdisDeviceStateD0 (fully powered) 0x2 NdisDeviceStateD1 (less-than-fully powered) 0x3 NdisDeviceStateD2 (more-less-than-fully powered) 0x4 NdisDeviceStateD3 (really-almost-not-powered-at-all)
Since I was interested in trying to get this information out of the collection of NIC devices on my laptop (along with other stuff), I hacked up a quick script and made it available below.

My problem is that although the OID_802_3* ioctl's are working, the OMP_PNP_QUERY_POWER one does not.

Any thoughts on what I am doing wrong?

Thanks

-Craig
UPDATE:...thats *PNP* not *PMP (sorry...)
UPDATE: I'm attaching the code here instead of in my scratchpad, by request:

use strict; use Win32API::File qw(CreateFile DeviceIoControl :FILE_SHARE_ :Misc); use Data::Dumper; sub IOCTL_NDIS_QUERY_GLOBAL_STATS () { 0x17 << 16 | 2 }; sub OID_802_3_PERMANENT_ADDRESS () { 0x01010101 }; sub OID_802_3_CURRENT_ADDRESS () { 0x01010102 }; sub OID_PNP_SET_POWER () { 0xFD010101 }; sub OID_PNP_QUERY_POWER () { 0xFD010102 }; # This routine graciously provided by PerlMonk almut # http://www.perlmonks.org/?node_id=580097 # http://www.perlmonks.org/?node_id=639099 sub NDIS_Query { my ($handle, $oid) = @_; my $nBytes = 0; my $buf = "\0"x10; my $oidp = pack("L", $oid); DeviceIoControl($handle, IOCTL_NDIS_QUERY_GLOBAL_STATS(), $oidp, length($oidp), $buf, length($buf), $nBytes, [] ); if($nBytes > 0) { #return join "-", unpack("(a2)*", unpack("H*", $buf) ); return(unpack("b*", $buf)); } return(); } # Get nic info via wmic (not available on all versions of windows)... my @devs = split(/^\s*\cM\n/m, `wmic nicconfig list /format:value`); shift(@devs); # Remove initial blank line # Iterate through each device... foreach my $d (@devs) { $d =~ s/\cM//g; # Grrrr, rotten windows my %node = split(/[=\n]/, $d); # Hashify information print "\n$node{Description} ($node{ServiceName}) \n"; # Make device to do the ioctl on... my $fname = '//./' . $node{SettingID}; #my $fname = '//Device/NPF_' . $node{SettingID}; my $fd = CreateFile($fname, 0, FILE_SHARE_READ(), [], OPEN_EXISTING(), 0, []); print "\t$fname "; if(!$fd) { print "$!\n"; next; } else { print "\n" }; # print info... print "\tCurrent Power :", NDIS_Query($fd, OID_PNP_QUERY_POWER()), + ":\n"; print "\tPermanent MAC :", NDIS_Query($fd, OID_802_3_PERMANENT_ADD +RESS()), ":\n"; print "\tCurrent MAC :", NDIS_Query($fd, OID_802_3_CURRENT_ADDRESS +()), ":\n"; #print Dumper(\%node); }

In reply to OID Power Status Query by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.