#include <iostream>

#include <unistd.h>


#include <sys/ioctl.h>

#include <sys/mouse.h>


// file open close using 

#include <fcntl.h>

// error printing using

#include <errno.h>


#define PSM_LEVEL_NATIVE    2

void checking(int number)

{

   printf(" error="" :%d\n",errno);<="" p="">

}


int main()

{

    int fd;

        // file descripter 

    int ret ;

    int level = PSM_LEVEL_NATIVE;    

    mousehw_t mhw;

      fd = open("/dev/sysmouse",O_RDWR);

      std::cout<<"FD :    "<<fd<<std::endl; 

      

      if(fd==-1)

       {

            std::cout<<"Open Error -> ErrorNumber : -> ";

            checking(1);

            std::cout<<""<<std::endl;

        }

// ret = ioctl(fd,MOUSE_SETLEVEL,&level);


 //    if(ret!=0)

  //   {

   //             checking(0);

    // }

    ret = ioctl(fd,MOUSE_GETHWINFO,&mhw);

    if(ret!=0)

    {

            checking(1);

    }


    

       std::cout<<"hw -> Type " <<mhw.type <<std::endl;

       std::cout<<"hw -> buttons " <<mhw.buttons <<std::endl;

       std::cout<<"hw -> model " <<mhw.model <<std::endl;

       std::cout<<"hw -> iftype " << mhw.iftype<<std::endl;

       std::cout<<"hw -> hwid "  <<mhw.hwid<<std::endl;    

    

    

    

    std::cout<<"closed fd"<<std::endl;




    return 0;

}


ioctl(int fd, Request 메시지, 파라미터)


Request 메시지중 MOUSE_GETHWINFO 를 보낼떄 받을 파라미터로 mousehw_t 를 보내게 된다. 물론 * 로

ioctl(fd,MOUSE_GETHWINFO,&mhw)를 보내게 되면

해당 구조체에 내용이 채워져서 나타나게 된다.

  typedef struct mousehw {
		int buttons;	/* number of buttons */
		int iftype;	/* I/F type */
		int type;	/* mouse/track ball/pad... */
		int model;	/* I/F dependent model ID */
		int hwid;	/* I/F dependent hardware ID */
	    } mousehw_t;
iftype 은 항상 MOUSE_IF_SYSMOUSE.

hwid 은 항상 0

model은 항상 MOUSE_MODEL_GENERIC Operation Level 0일때 더 높은 레벨의 경우에 MOUSE_MODEL_XXX

type 은 장치 타입이다. :  MOUSE_MOUSE, MOUSE_TRACKBALL, MOUSE_STICK, MOUSE_PAD, or MOUSE_UNKNOWN.


일단 마우스의 정보 정돈 가져올수 있게 된다. 



'GNU > FreeBSD' 카테고리의 다른 글

Mouse_Control - 5 번째(Consio.h)  (0) 2016.07.06
Mouse_Control - 4 번째(Consio.h)  (0) 2016.07.04
COMMAND - top  (0) 2016.07.04
Unix Errno 표기  (0) 2016.07.04
Mouse_Control - 3 일차  (0) 2016.07.01

카테고리 위 설명


load averages : 로드 평균


시스템 스케줄러의 런 큐에 대기하고 있는 쓰레드의 개수 


일반적으로 시스템의 부하는 로드값이 높은 것을 의미함.... 차례대로 1분, 5분 15분 간의 평균 로드값을 나타냄


모든 프로세스 상태 개요 총개수와 각각의 상태를 말함


CPU : 현재 CPU 에 의해 실행되고있는 프로세스 갯수 


running  : 실행할 수 있는 프로세스 개수, On CPU 와 Running인 프로세스가 많다는 것은 시스템의 부하가 많다는 뜻


Sleeping : 외부 이벤트 /입력을 기다리공 ㅣㅆ는 프로세스 개수


Stopped : Ctrl + Z 와 같은 정지 시그널로 정지왿 ㄴ프로세스 개수 


Swapped : 디스크로 스왑되고 있는 프로세스 개수 0, 0이어야 함


Zombie : 종료는 되었지만 다른 이유로 정리되지 않고 기다리고있는 프로세스개수, 작은값 혹은 0 이어야 한다. 


CPU 상태


idle : 아무것도 하지 않음  User : 유저 프로세스 실행 



K : Kilobyte


M: Megabyte


G: Gigabyte


%: 1/100





top 실행시 나오는 카테고리


PID : 프로세스 id

-> 마지막으로 할당된 PID 


USERNAME

-> 프로세스 소유자 이름   -> 사용중인 유저 네임을 뜻함 (root 혹은 계정명)


THR

-> LWP 또는 스레드 개수 (Light-Weight Process, SUN 은 쓰레드와 LWP는 다르지만 유닉스 쓰레드가 LWP를 이용해 구현되기 때문에 비슷한 개념)


PRI

-> 우선순위 유저 프로세스의 경우 범위는 0~59 값이 높을수록 우선순위가 높음 


NICE

-> 우선순위를 결정하기 위해서 커널에서 참고하는 나이스 값 사용자가 설정할 수 있으며 설정하지 않으면 0 이 값이 낮을 경우 우선순위가 높게 측정 ㅗ딜 수 있음 


SIZE

-> 프로세스에 할당된 총 메모리  (Physical + Logical ) 


RES

-> 프로세스에 의해 사용된 물리 메모리의 양 (Resident set size)


STATE

-> CPU, RUN, SLEEP, STOP, SWAP, ZOMB 


C

-> 흠 아직



TIME

-> 프로세스가 사용한 CPU 시간 1:00 1분 동안 100% 소모  


WCPU(Weighted CPU) or CPU ( Shift C 로 변환 가능) 현재 프로세스의 총 CPU 대비 사용률 

4개의 CPU 에서 25%라 나왔다면 이중 1개의 CPU 를 100% 소비하고 있다고 해석할 수 있다.


지금 4개 쓰는데 180% 뜨면

문제 있는거 아닌가.. 뭐지;;;;


COMMAND

-> 프로세스를 실행한 커맨드.






CPU 1개당 100%로 계산 


'GNU > FreeBSD' 카테고리의 다른 글

Mouse_Control - 4 번째(Consio.h)  (0) 2016.07.04
Mouse_Control - 4 번째  (0) 2016.07.04
Unix Errno 표기  (0) 2016.07.04
Mouse_Control - 3 일차  (0) 2016.07.01
Mouse_Control - 2 일차  (0) 2016.06.30

#define EPERM   1   /* Operation not permitted      */
#define ENOENT  2   /* No such file or directory        */
#define ESRCH   3   /* No such process          */
#define EINTR   4   /* interrupted system call      */
#define EIO 5   /* I/O error                */
#define ENXIO   6   /* No such device or address        */
#define E2BIG   7   /* Arg list too long            */
#define ENOEXEC 8   /* Exec format error            */
#define EBADF   9   /* Bad file descriptor          */
#define ECHILD  10  /* No child processes           */
#define EAGAIN  11  /* Resource temporarily unavailable */
#define ENOMEM  12  /* Not enough space         */
#define EACCES  13  /* Permission denied            */
#define EFAULT  14  /* Bad address              */
#define ENOTBLK 15  /* Block device required        */
#define EBUSY   16  /* Resource busy            */
#define EEXIST  17  /* File exists              */
#define EXDEV   18  /* Improper link            */
#define ENODEV  19  /* No such device           */
#define ENOTDIR 20  /* Not a directory          */
#define EISDIR  21  /* Is a directory           */
#define EINVAL  22  /* Invalid argument         */
#define ENFILE  23  /* Too many open files in system    */
#define EMFILE  24  /* Too many open files          */
#define ENOTTY  25  /* Inappropriate I/O control operation  */
#define ETXTBSY 26  /* Text file busy           */
#define EFBIG   27  /* File too large           */
#define ENOSPC  28  /* No space left on device      */
#define ESPIPE  29  /* Invalid seek             */
#define EROFS   30  /* Read only file system        */
#define EMLINK  31  /* Too many links           */
#define EPIPE   32  /* Broken pipe              */
#define EDOM    33  /* Domain error within math function    */
#define ERANGE  34  /* Result too large         */
#define ENOMSG  35  /* No message of desired type       */
#define EIDRM   36  /* Identifier removed           */
#define ECHRNG  37  /* Channel number out of range      */
#define EL2NSYNC 38 /* Level 2 not synchronized     */
#define EL3HLT  39  /* Level 3 halted           */
#define EL3RST  40  /* Level 3 reset            */
#define ELNRNG  41  /* Link number out of range     */
#define EUNATCH 42  /* Protocol driver not attached     */
#define ENOCSI  43  /* No CSI structure available       */
#define EL2HLT  44  /* Level 2 halted           */
#define EDEADLK 45  /* Resource deadlock avoided        */
#define ENOTREADY   46  /* Device not ready     */
#define EWRPROTECT  47  /* Write-protected media    */
#define EFORMAT     48  /* Unformatted media        */
#define ENOLCK      49  /* No locks available       */
#define ENOCONNECT      50      /* no connection                */
#define ESTALE          52      /* no filesystem                */
#define EDIST       53  /* old, currently unused AIX errno*/
#define EWOULDBLOCK     EAGAIN   /* Operation would block   */
#define EWOULDBLOCK 54
#define EINPROGRESS     55      /* Operation now in progress */
#define EALREADY        56      /* Operation already in progress */
#define ENOTSOCK        57      /* Socket operation on non-socket */
#define EDESTADDRREQ    58      /* Destination address required */
#define EDESTADDREQ     EDESTADDRREQ /* Destination address required */
#define EMSGSIZE        59      /* Message too long */
#define EPROTOTYPE      60      /* Protocol wrong type for socket */
#define ENOPROTOOPT     61      /* Protocol not available */
#define EPROTONOSUPPORT 62      /* Protocol not supported */
#define ESOCKTNOSUPPORT 63      /* Socket type not supported */
#define EOPNOTSUPP      64      /* Operation not supported on socket */
#define EPFNOSUPPORT    65      /* Protocol family not supported */
#define EAFNOSUPPORT    66      /* Address family not supported by protocol family */
#define EADDRINUSE      67      /* Address already in use */
#define EADDRNOTAVAIL   68      /* Can't assign requested address */
#define ENETDOWN        69      /* Network is down */
#define ENETUNREACH     70      /* Network is unreachable */
#define ENETRESET       71      /* Network dropped connection on reset */
#define ECONNABORTED    72      /* Software caused connection abort */
#define ECONNRESET      73      /* Connection reset by peer */
#define ENOBUFS         74      /* No buffer space available */
#define EISCONN         75      /* Socket is already connected */
#define ENOTCONN        76      /* Socket is not connected */
#define ESHUTDOWN       77      /* Can't send after socket shutdown */
#define ETIMEDOUT       78      /* Connection timed out */
#define ECONNREFUSED    79      /* Connection refused */
#define EHOSTDOWN       80      /* Host is down */
#define EHOSTUNREACH    81      /* No route to host */
#define ERESTART    82  /* restart the system call */
#define EPROCLIM    83  /* Too many processes */
#define EUSERS      84  /* Too many users */
#define ELOOP       85  /* Too many levels of symbolic links      */
#define ENAMETOOLONG    86  /* File name too long             */
#define ENOTEMPTY   EEXIST  /* Directory not empty */
#define ENOTEMPTY   87
#define EDQUOT      88  /* Disc quota exceeded */
#define ECORRUPT        89      /* Invalid file system control data */
#define EREMOTE     93  /* Item is not local to host */
#define ENOSYS      109 /* Function not implemented  POSIX */
#define EMEDIA      110     /* media surface error */
#define ESOFT           111     /* I/O completed, but needs relocation */
#define ENOATTR     112     /* no attribute found */
#define ESAD        113 /* security authentication denied */
#define ENOTRUST    114 /* not a trusted program */
#define ETOOMANYREFS    115     /* Too many references: can't splice */
#define EILSEQ      116     /* Invalid wide character */
#define ECANCELED   117     /* asynchronous i/o cancelled */
#define ENOSR       118 /* temp out of streams resources */
#define ETIME       119 /* I_STR ioctl timed out */
#define EBADMSG     120 /* wrong message type at stream head */
#define EPROTO      121 /* STREAMS protocol error */
#define ENODATA     122 /* no message ready at stream head */
#define ENOSTR      123 /* fd is not a stream */
#define ECLONEME    ERESTART /* this is the way we clone a stream ... */
#define ENOTSUP     124 /* POSIX threads unsupported value */
#define EMULTIHOP       125     /* multihop is not allowed */
#define ENOLINK         126     /* the link has been severed */
#define EOVERFLOW       127     /* value too large to be stored in data type */

'GNU > FreeBSD' 카테고리의 다른 글

Mouse_Control - 4 번째  (0) 2016.07.04
COMMAND - top  (0) 2016.07.04
Mouse_Control - 3 일차  (0) 2016.07.01
Mouse_Control - 2 일차  (0) 2016.06.30
Mouse_Control - 1 일차  (0) 2016.06.29
기본적으로 운영체제는 

1. 사용자 공간


2. 커널 

두개의공간으로 나누어져 있다. 문서 편집기 익스플로러같은 응용 프로그램코드는 사용자 공간에 

있으며 네트워크 스택, 같은 OS기반은 코드는 커널에 상주한다.

커널 코드는 민감한 리소스를 관리하며 응용 프로그램 사이의 보안과 신뢰 장벽을 제공한다.

이러한 까닭에 사용자 모드 응용 프로그램은 CPU 에 의해 커널 리소스를 직접 접근하는 것을 막는다.

사용자 공간 응용 프로그램은 사용자 -> 커널로 이동하는 특별한 서브루틴 콜인 시스템 콜의 수단으로

기본 커널의 대부분의 요청을 취한다.  보통 시스템 콜 벡터와 함께 추가되며 여기서 요청자는

원하는 시스템 콜을 색인 숫자로 기억한다.  하지만 이런 시스템 콜에도 드라이버 장치는 막혀있다.

대부분의 하드웨어 주변 기기는 반드시 커널 안에서 직접 접근 하여야 한다. 

그러나 사용자 코드는 장치와 통신해야 하는 경우가 있다. 


일단 마우스 장치에 대해서 

/dev/해당 관련 마우스 장치에 파일을

open ()으로 열어서 리턴되는 fd(File descriptor) 값을 이용하여서


#include <sys/ioctl.h>

int ioctl(int fd, int request, argp);


ioctl (I/O Control)을 통해서 장치 제어를 한다. 


ioctl 의 경우 (int fd, int request, argp) 로 들어오게 된다.


fd는 open으로 인해 반환된 fd(file descriptor)

request : 드라이버에서 취해야 할 명령을 보낸다. 


성공일시 0 값 실패시 -1 반환 


-1을 얻었을시에 error 값을 참조하면 문제 확인 가능(EFAULT argp는 접근할수 없는 메모리 영역)

ENOTTY : fd는 문자 디바이스 파일과 연관되어있지 않다.


EINVAL : 디바이스파일에 연동된 드라이버가 request 또는 argp처리 불가능 


// 

int fd  ; // file descriptor


int ret;

int level = 2;

mousehw_t mhw;


fd = open=("/dev/장치명",O_RDWR);

if(fd==-1)  // -1 이면 에러

{

std::cout<<"Open Error -> Error Number : - > " ;

checking();

std::cout<<""<<std::endl;

}

std::cout<<"Current File Descriptor :: ->>>>  <<fd <<std::endl;


ret = ioctl(fd,MOUSE_SETLEVEL,&level);









'GNU > FreeBSD' 카테고리의 다른 글

COMMAND - top  (0) 2016.07.04
Unix Errno 표기  (0) 2016.07.04
Mouse_Control - 2 일차  (0) 2016.06.30
Mouse_Control - 1 일차  (0) 2016.06.29
Free BSD 유용한 명령어  (0) 2016.06.14


'GNU > FreeBSD' 카테고리의 다른 글

COMMAND - top  (0) 2016.07.04
Unix Errno 표기  (0) 2016.07.04
Mouse_Control - 3 일차  (0) 2016.07.01
Mouse_Control - 1 일차  (0) 2016.06.29
Free BSD 유용한 명령어  (0) 2016.06.14

후킹 -

컴퓨터 프로그램과 S/W 구성 요소간에 발생하는 함수 호출, 메시지 등을 중간에 바꾸거나 가로채는 방법 기술


간섭된 함수를 호출, 이벤트 를 처리하는 코드 = Hook 라고함 


후킹은 이벤트를 훔쳐오는 방식이다.  (OS의 구조를 알아야 한다.)


마우스 후킹 


OS 내에서 이동되는 마우스 를 후킹 한다. 


리눅스 자체에서 마우스를 제어 한다. 


// 


연결 마우스에 대한 파일 

   /dev/cuau%d      serial ports
     /dev/mse%d	      bus and InPort mouse device
     /dev/psm%d	      PS/2 mouse device
     /dev/sysmouse    virtual mouse device
     /dev/ums%d	      USB mouse	device

연결된 포트에 따라서 파라미터로 넘기고 이에 대한 제어를 해야 한다는 것 정도 


open(), write(), ioctl () 사용하여 sysmouse를 제어한다. mosued 에 대한 정보가 필요 


'GNU > FreeBSD' 카테고리의 다른 글

COMMAND - top  (0) 2016.07.04
Unix Errno 표기  (0) 2016.07.04
Mouse_Control - 3 일차  (0) 2016.07.01
Mouse_Control - 2 일차  (0) 2016.06.30
Free BSD 유용한 명령어  (0) 2016.06.14

FreeBSD 유용한 명령어 (이글에다가 지속적으로 업데이트 )




pciconf -lv  디바이스 장치 및 그래픽 카드 확인 



ldd 


ldd /system/**  **의 붙어있는 라이브러리들을 보여줌



LD_LIBRARY_PATH /etc/profile에 있음 



'GNU > FreeBSD' 카테고리의 다른 글

COMMAND - top  (0) 2016.07.04
Unix Errno 표기  (0) 2016.07.04
Mouse_Control - 3 일차  (0) 2016.07.01
Mouse_Control - 2 일차  (0) 2016.06.30
Mouse_Control - 1 일차  (0) 2016.06.29

+ Recent posts