jtagsock.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <errno.h>
00042 #include <signal.h>
00043 #include <stdio.h>
00044 #include <unistd.h>
00045 #include <sys/types.h>
00046 #include <sys/socket.h>
00047 #include <sys/wait.h>
00048 #include <netinet/in.h>
00049 #include <netdb.h>
00050 #include <asm/ioctls.h>
00051 #include "jtagsock.h"
00052 extern int config_gdbserver_quitgdb;
00053
00054
00055
00056
00057
00058
00059
00060 int fJTAGSOCK_Establish (unsigned short us_portnum)
00061 {
00062 char c_myname[dJTAGSOCK_MAXHOSTNAME+1];
00063 int i_socket;
00064 struct sockaddr_in st_sa;
00065 struct hostent *st_hp;
00066
00067
00068 memset(&st_sa, 0, sizeof(struct sockaddr_in));
00069
00070
00071 gethostname(c_myname, dJTAGSOCK_MAXHOSTNAME);
00072
00073
00074 st_hp=gethostbyname(c_myname);
00075 if (st_hp == NULL) return(-1);
00076
00077 st_sa.sin_family = st_hp->h_addrtype;
00078 st_sa.sin_port = htons(us_portnum);
00079
00080
00081 i_socket = socket(AF_INET, SOCK_STREAM, 0);
00082 if (i_socket < 0) return(-1);
00083
00084
00085 if (bind(i_socket, (struct sockaddr *)&st_sa, sizeof(struct sockaddr_in)) < 0)
00086 {
00087
00088 close(i_socket);
00089 return(-1);
00090 }
00091
00092
00093 listen(i_socket, dJTAGSOCK_NUM_CONNECTIONS);
00094 return(i_socket);
00095 }
00096
00097
00098
00099
00100
00101
00102 int fJTAGSOCK_GetConnection(int i_socket)
00103 {
00104 int i_newsocket;
00105
00106
00107 do{
00108 int n;
00109 char buf[100];
00110 i_newsocket = accept(i_socket,NULL,NULL);
00111 ioctl(0,FIONREAD,&n);
00112 if(n)
00113 {
00114 read(0,buf,n);
00115 buf[n] = 0;
00116 do_cmd(buf);
00117 if(config_gdbserver_quitgdb)return -1;
00118 }
00119 }
00120 while(i_newsocket == -1);
00121
00122 if (i_newsocket < 0) return(-1);
00123
00124 return(i_newsocket);
00125 }
00126
00127
00128
00129
00130
00131
00132 int fJTAGSOCK_ReadByte (int i_socket, char *pc_byte)
00133 {
00134 return(read(i_socket, pc_byte, 0x01));
00135 }
00136
00137
00138
00139
00140
00141
00142 int fJTAGSOCK_WriteByte (int i_socket, char c_byte)
00143 {
00144 #if 1
00145 while(write(i_socket, &c_byte, 0x01) != 0x01);
00146 #else
00147 volatile int test=0;
00148 printf("haha-1\n");
00149 test = write(i_socket, &c_byte, 0x01);
00150 printf("haha-2 : test : %d\n",test);
00151 while(test != 0x01)
00152 {
00153 printf("haha-3\n");
00154 test = write(i_socket, &c_byte, 0x01);
00155 printf("haha-4 test : %d\n",test);
00156 }
00157 #endif
00158 return(1);
00159 }