| #include <stdio.h> |
| #include <fcntl.h> |
| #include <unistd.h> |
| #include <string.h> |
| #include <sys/ioctl.h> |
| |
| int main() |
| { |
| int fdusb, fdpm; |
| int i; |
| |
| if ( (fdusb = open("/dev/cp_lkm_usb", O_RDWR)) < 0 ) { |
| printf("%s() open failed\n", __FUNCTION__); |
| return fdusb; |
| } |
| |
| if ( (fdpm = open("/dev/cp_lkm_pm", O_RDWR)) < 0 ) { |
| printf("%s() open failed\n", __FUNCTION__); |
| close(fdusb); |
| return fdpm; |
| } |
| |
| printf("testing write fd:%d\n", fdusb); |
| char buffer[52]; |
| for (i=0; i < 52; i++) { |
| if (i < 26) { |
| buffer[i] = 'A' + i; |
| } else { |
| buffer[i] = 'a' + i; |
| } |
| } |
| int nwrite = write(fdusb, buffer, 52); |
| if (nwrite != 52) { |
| printf("%s() - write error -> %d of %d written\n", __FUNCTION__, nwrite, 52); |
| } |
| |
| printf("testing write fd:%d\n", fdpm); |
| char bufferpm[26]; |
| for (i=0; i < 26; i++) { |
| bufferpm[i] = 'a' + i; |
| } |
| nwrite = write(fdpm, bufferpm, 26); |
| if (nwrite != 26) { |
| printf("%s() - write error -> %d of %d written\n", __FUNCTION__, nwrite, 26); |
| } |
| |
| char read_buffer[52]; |
| int nread = read(fdusb, read_buffer, 52); |
| if (nread != 52) { |
| printf("%s() - read error -> %d of %d read\n", __FUNCTION__, nread, 52); |
| } |
| if (memcmp(buffer, read_buffer, 52)) { |
| printf("%s() - read/write memcmp failed\n", __FUNCTION__); |
| } else { |
| printf("%s() - read/write memcmp succeeded\n", __FUNCTION__); |
| } |
| |
| nread = read(fdpm, read_buffer, 26); |
| if (nread != 26) { |
| printf("%s() - read error -> %d of %d read\n", __FUNCTION__, nread, 26); |
| } |
| if (memcmp(bufferpm, read_buffer, 26)) { |
| printf("%s() - read/write memcmp failed %s\n", __FUNCTION__, read_buffer); |
| } else { |
| printf("%s() - read/write memcmp succeeded\n", __FUNCTION__); |
| } |
| |
| |
| printf("%s() - testing ioctl\n", __FUNCTION__); |
| |
| int ioctl_resl = ioctl(fdusb, 322, 0xdeadbeef); |
| printf("%s() - ioctl resl:%d\n", __FUNCTION__, ioctl_resl); |
| |
| close(fdusb); |
| close(fdpm); |
| |
| return 0; |
| } |