Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <rpc/rpc.h>
  4. #include <sys/select.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7. #include <arpa/inet.h>
  8. #include <rpc/rpc_router_ioctl.h>
  9. #include <debug.h>
  10. #include <pthread.h>
  11.  
  12. typedef struct registered_server_struct {
  13.         /* MUST BE AT OFFSET ZERO!  The client code assumes this when it overwrites
  14.          *        the XDR for server entries which represent a callback client.  Those
  15.          *               server entries do not have their own XDRs.
  16.          *                   */
  17.         XDR *xdr;
  18.             /* Because the xdr is NULL for callback clients (as opposed to true
  19.          *        servers), we keep track of the program number and version number in this
  20.          *               structure as well.
  21.          *                   */
  22.             rpcprog_t x_prog; /* program number */
  23.             rpcvers_t x_vers; /* program version */
  24.  
  25.                 int active;
  26.                 struct registered_server_struct *next;
  27.                     SVCXPRT *xprt;
  28.                     __dispatch_fn_t dispatch;
  29. } registered_server;
  30.  
  31. struct SVCXPRT {
  32.         fd_set fdset;
  33.             int max_fd;
  34.             pthread_attr_t thread_attr;
  35.                 pthread_t  svc_thread;
  36.                 pthread_mutexattr_t lock_attr;
  37.                     pthread_mutex_t lock;
  38.                     registered_server *servers;
  39.                         volatile int num_servers;
  40. };
  41.  
  42.  
  43.  
  44. #define SEND_VAL(x) do { \
  45.     val=x;\
  46.     XDR_SEND_UINT32(clnt, &val);\
  47. } while(0);
  48.  
  49. uint32_t client_ID;
  50.  
  51. bool_t xdr_args(XDR* clnt, void *data) {
  52.     uint32_t val=0;
  53.     switch((int)data) {
  54.         case 0:
  55.             //pdsm_client_init
  56.             SEND_VAL(1);//INIT_PD
  57.             return 1;
  58.             break;
  59.         case 1:
  60.             SEND_VAL(client_ID);
  61.             SEND_VAL(0x0049f3a0);
  62.             SEND_VAL(0xa970bf81);
  63.             SEND_VAL(0x0);
  64.             SEND_VAL(0xf310ffff);//0xf310ffff ?
  65.             //SEND_VAL(0xF310FFFF);//0xf310ffff ?
  66.             SEND_VAL(0xa970bee1);
  67.             return 1;
  68.             break;
  69.         case 2:
  70.             //pdsm_client_ext_status_reg(0xDA3, 0x00, 0x00, 0x00, 0x04, -1);
  71.             SEND_VAL(client_ID);
  72.             SEND_VAL(0x0049f3a0);
  73.             SEND_VAL(0xa970bf21); //SEND_VAL(0x00); ?
  74.             SEND_VAL(0x0);
  75.             SEND_VAL(0x00000007);
  76.             SEND_VAL(0xa970be81);
  77.             return 1;
  78.         case 3:
  79.         case 6:
  80.             SEND_VAL(client_ID);
  81.             return 1;
  82.         case 4:
  83.         case 7:
  84. #if 0
  85.             SEND_VAL((data==4) ? 0xb : 0xa);//0xA ?
  86.             SEND_VAL(0x0);
  87.             SEND_VAL(0x1);
  88.             SEND_VAL(0x1);
  89.             SEND_VAL(0x1);
  90.             SEND_VAL(0x3B9AC9FF);
  91.             SEND_VAL(0x1);
  92.             SEND_VAL(0x0);
  93.             SEND_VAL(0x0);
  94.             SEND_VAL(0x0);
  95.             SEND_VAL(0x0);
  96.             SEND_VAL(0x0);
  97.             SEND_VAL(0x0);
  98.             SEND_VAL(0x0);
  99.             SEND_VAL(0x0);
  100.             SEND_VAL(0x0);
  101.             SEND_VAL(0x0);
  102.             SEND_VAL(0x0);
  103.             SEND_VAL(0x0);
  104.             SEND_VAL(0x0);
  105.             SEND_VAL(0x0);
  106.             SEND_VAL(0x0);
  107.             SEND_VAL(0x0);
  108.             SEND_VAL(0x0);
  109.             SEND_VAL(0x1);
  110.             SEND_VAL(0x32);
  111.             SEND_VAL(0x2);
  112.             SEND_VAL(client_ID);
  113. #endif
  114.             SEND_VAL(0xa970be41);
  115.             SEND_VAL(0x0049f3a0);
  116.                SEND_VAL(    00000001 );
  117.                    SEND_VAL(00000001 );
  118.                  SEND_VAL(00000002 );
  119.                  SEND_VAL(0x0000000a );
  120.                  SEND_VAL(00000001 );
  121.                  SEND_VAL(00000001 );
  122.                  SEND_VAL(00000000 );
  123.                  SEND_VAL(0x480eddc0 );
  124.                  SEND_VAL(0x00006c1c );
  125.                  SEND_VAL(00000000 );
  126.                  SEND_VAL(00000000 );
  127.                  SEND_VAL(00000000 );
  128.                  SEND_VAL(00000000 );
  129.                  SEND_VAL(00000000 );
  130.                  SEND_VAL(0);
  131.                 SEND_VAL(00000000 );
  132.                 SEND_VAL(00000000 );
  133.                 SEND_VAL(00000000 );
  134.                 SEND_VAL(00000000 );
  135.                 SEND_VAL(00000000 );
  136.                 SEND_VAL(00000000 );
  137.                 SEND_VAL(00000000 );
  138.                 SEND_VAL(00000001 );
  139.                 SEND_VAL(0x00000032 );
  140.                 SEND_VAL(0x00000078 );
  141.             SEND_VAL(client_ID);
  142.  
  143.             return 1;
  144.         case 5:
  145.             //pdsm_end_session
  146.             SEND_VAL(0x0b);
  147.             SEND_VAL(0x00);
  148.             SEND_VAL(0x00);
  149.             SEND_VAL(client_ID);
  150.             return 1;
  151.         default:
  152.             return 0;
  153.             break;
  154.            
  155.     };
  156. }
  157.  
  158. bool_t xdr_result(XDR* clnt, void *data) {
  159.     uint32_t val=0;
  160.     switch((int)data) {
  161.         case 0:
  162.             XDR_RECV_UINT32(clnt, &val);
  163.             client_ID=val;
  164.             printf("\t=%d\n", val);
  165.             return 1;
  166.         case 1:
  167.         case 2:
  168.         case 3:
  169.         case 4:
  170.         case 5:
  171.         case 6:
  172.         case 7:
  173.         case 42:
  174.             XDR_RECV_UINT32(clnt, &val);
  175.             printf("\t=%d\n", val);
  176.             return 1;
  177.             break;
  178.         default:
  179.             return 0;
  180.             break;
  181.     };
  182.    
  183. }
  184.  
  185. void dispatch(struct svc_req* a, registered_server* svc) {
  186.     int i;
  187.     uint32_t *data=svc->xdr->in_msg;
  188.     printf("received some kind of event\n");
  189.     for(i=0;i< svc->xdr->in_len/4;++i) {
  190.         printf("%08x ", ntohl(data[i]));
  191.     }
  192.     printf("\n");
  193. }
  194.  
  195. int main(int argc, char **argv, char **envp) {
  196.     //timeout isn't taken in account by librpc
  197.     struct timeval timeout;
  198.     struct CLIENT *clnt=clnt_create(NULL, 0x3000005B, 0x90380d3d, NULL);
  199.     int i;
  200.     SVCXPRT *svc=svcrtr_create();
  201.     xprt_register(svc);
  202.     svc_register(svc, 0x3100005b, 0xb93145f7, dispatch,0);
  203.     if(!clnt) {
  204.         printf("Failed creating client\n");
  205.         return -1;
  206.     }
  207.     if(!svc) {
  208.         printf("Failed creating server\n");
  209.         return -2;
  210.     }
  211.  
  212.     printf("pdsm_client_deact(0xDA3);\n");
  213.     if(clnt_call(clnt, 0x9, xdr_args, 6, xdr_result, 6, timeout)) {
  214.         printf("\tfailed\n");
  215.         return -1;
  216.     }
  217.  
  218.     printf("pdsm_client_init(2)\n");
  219.     if(clnt_call(clnt, 0x2, xdr_args, 0, xdr_result, 0, timeout)) {
  220.         printf("\tfailed\n");
  221.         return -1;
  222.     }
  223.  
  224.  
  225.     printf("pdsm_client_pd_reg(0x%x, 0x00, 0x00, 0x00, 0xF3F0FFFF, -1);\n", client_ID);
  226.     if(clnt_call(clnt, 0x4, xdr_args, 1, xdr_result, 1, timeout)) {
  227.         printf("\tfailed\n");
  228.         return -1;
  229.     }
  230.  
  231.     printf("pdsm_client_ext_status_reg(0xDA3, 0x00, 0x01, 0x00, 0x04, -1);\n");
  232.     if(clnt_call(clnt, 0x7, xdr_args, 2, xdr_result, 2, timeout)) {
  233.         printf("\tfailed\n");
  234.         return -1;
  235.     }
  236.  
  237.     printf("pdsm_client_act(0xDA3);\n");
  238.     if(clnt_call(clnt, 0x9, xdr_args, 3, xdr_result, 3, timeout)) {
  239.         printf("\tfailed\n");
  240.         return -1;
  241.     }
  242.  
  243.     printf("BIG BREATH\n");
  244.     printf("BIGGER BREATH\n");
  245.  
  246.     /*
  247.     printf("pdsm_client_end_session(0xb, 0x00, 0x00, 0xda3);\n");
  248.     if(clnt_call(clnt, 0xc, xdr_args, 5, xdr_result, 5, timeout)) {
  249.         printf("\tfailed\n");
  250.         return -1;
  251.     }*/
  252.     printf("pdsm_client_get_position(0xda3, 0xb);\n");
  253.     if(clnt_call(clnt, 0xB, xdr_args, 4, xdr_result, 4, timeout)) {
  254.         printf("\tfailed\n");
  255.         return -1;
  256.     }
  257.  
  258.     return 0;
  259.     while(1) {
  260.         printf("pdsm_client_get_position(0xDA3, 0xa);\n");
  261.         if(clnt_call(clnt, 0xB, xdr_args, 7, xdr_result, 7, timeout)) {
  262.             printf("\tfailed\n");
  263.             return -1;
  264.         }
  265.         sleep(1);
  266.     }
  267.  
  268.     /*
  269.     for(i=0;i<256;++i) {
  270.         printf("clk_regime_sec_msm_get_clk_freq_khz(%d);\n", i);
  271.         if(clnt_call(clnt, 0x24, xdr_args, i, xdr_result, 42, timeout)) {
  272.             printf("\tfailed\n");
  273.             return -1;
  274.         }
  275.     }*/
  276.     return 0;
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement