1 /*******************************************************************
2 uLan Communication - simple test client
4 ul_spy.c - message monitor
6 (C) Copyright 1996,1999 by Pavel Pisa
8 The uLan driver is distributed under the Gnu General Public Licence.
9 See file COPYING for details.
10 *******************************************************************/
19 #include <sys/types.h>
22 #include <ul_lib/ulan.h>
24 int si_long(char **ps,long *val,int base)
27 *val=strtol(*ps,&p,base);
33 int add_to_arr(void **pdata,int *plen,int base,char *str)
40 while(*s && strchr(", \t:;",*s)) s++;
42 if(si_long(&s,&val,base)<0){
49 p=realloc(*pdata,*plen+1);
50 if(p==NULL) return -1;
53 ((uchar*)p)[*plen]=val;
59 /*******************************************************************/
61 char *ul_dev_name = UL_DEV_NAME;
64 uchar *msg_data= NULL;
73 int print_modules(int max_addr)
81 ul_fd=ul_open(ul_dev_name, NULL);
82 if(ul_fd==UL_FD_INVALID)
83 { perror("print_modules : uLan open failed");return -1;};
84 for(i=1;i<=max_addr;i++)
86 ret=ul_send_query_wait(ul_fd,i,UL_CMD_SID,
87 UL_BFL_NORE|UL_BFL_PRQ,NULL,0,&buf,&buf_len);
91 for(ret=0;(ret<buf_len)&&*p;ret++,p++);
93 fwrite(buf,ret,1,stdout);
103 int debug_kernel(int debug_msk)
106 ul_fd=ul_open(ul_dev_name, NULL);
107 if(ul_fd==UL_FD_INVALID)
108 { perror("debug_kernel : uLan open failed");return -1;};
109 ret=ul_drv_debflg(ul_fd,debug_msk);
117 ul_fd=ul_open(ul_dev_name, NULL);
118 if(ul_fd==UL_FD_INVALID)
119 { perror("log_kernel : uLan open failed");return -1;};
122 ret=DeviceIoControl(ul_fd,UL_KLOGBLL,
124 &bytes_ret,NULL)?0:-1;
126 #elif !defined(UL_DRV_IN_LIB)
127 ret=ioctl(ul_fd,UL_KLOGBLL,0);
133 int send_message(void)
141 ul_fd=ul_open(ul_dev_name, NULL);
142 if(ul_fd==UL_FD_INVALID)
143 { perror("send_message : uLan open failed");return -1;};
146 ret=ul_send_command_wait(ul_fd,msg_module,msg_cmd,msg_flg,
148 fprintf(stderr,"ul_send_command_wait ret %d\n",ret);
150 ret=ul_send_query_wait(ul_fd,msg_module,msg_cmd,msg_flg,
151 msg_data,msg_len,(void**)&bufout,&lenout);
152 fprintf(stderr,"ul_send_query_wait ret %d\n",ret);
153 for(i=0;i<lenout;i++) printf("0x%02x ",bufout[i]);
157 if(bufout!=NULL) free(bufout);
166 printf("usage: ul_sendmsg <parameters> <hex_bytes>\n");
167 printf(" -d, --uldev <name> name of uLan device [/dev/ulan]\n");
168 printf(" -m, --module <num> destination module address\n");
169 printf(" -c, --command <num> command\n");
170 printf(" -f, --flags <num> flags\n");
171 printf(" -q, --query send query type message\n");
172 printf(" -p, --print <max> print modules to max address\n");
173 printf(" --debug-kernel <m> flags to debug kernel\n");
174 printf(" -V, --version show version\n");
175 printf(" -h, --help this usage screen\n");
178 int main(int argc,char *argv[])
180 static struct option long_opts[] = {
181 { "uldev", 1, 0, 'd' },
182 { "module",1, 0, 'm' },
183 { "command",1,0, 'c' },
184 { "flags", 1, 0, 'f' },
185 { "query", 0, 0, 'q' },
186 { "print", 1, 0, 'p' },
187 { "version",0,0, 'V' },
188 { "help", 0, 0, 'h' },
189 { "debug-kernel", 1, 0, 'D' },
190 { "log-kernel", 0, 0, 'L' },
195 #ifndef HAS_GETOPT_LONG
196 while ((opt = getopt(argc, argv, "d:m:c:f:qp:VhD:L")) != EOF)
198 while ((opt = getopt_long(argc, argv, "d:m:c:f:qp:VhD:L",
199 &long_opts[0], NULL)) != EOF)
206 msg_module = strtol(optarg,NULL,0);
209 msg_cmd = strtol(optarg,NULL,0);
212 msg_flg = strtol(optarg,NULL,0);
218 prt_modules = strtol(optarg,NULL,0);
221 debugk = strtol(optarg,NULL,0);
228 fputs("uLan send message v0.7\n", stdout);
233 exit(opt == 'h' ? 0 : 1);
236 if(debugk_flg) debug_kernel(debugk);
238 if(logk_flg) log_kernel();
240 if(prt_modules) print_modules(prt_modules);
242 for(;optind<argc;optind++){
243 if(add_to_arr((void**)&msg_data,&msg_len,0,argv[optind])<0){
244 fprintf(stderr,"%s: incorrect message data \"%s\"\n",argv[0],argv[optind]);