int gtpVMEGetHostname(char **rval, int pFlag) { int slen=0, done=0; int i=0, ibyte=0; unsigned int read1, read2, hn[4]; char hostname[60], byte_c[2]; unsigned int shift=0, mask=0, byte=0; if(vGTPp==NULL) { printf("%s: ERROR: GTP not initialized\n",__FUNCTION__); return ERROR; } memset((char*)hostname,0,sizeof(hostname)); GTPLOCK; for(i=0; i<4; i++) { read1 = vmeRead32(&vGTPp->Hostname[2*i])&0xFFFF; read2 = vmeRead32(&vGTPp->Hostname[(2*i+1)])&0xFFFF; read1 = SSWAP(read1); read2 = SSWAP(read2); hn[i] = (read1) | (read2<<16); } GTPUNLOCK; strcpy(hostname,""); for(i=0; i<4; i++) { if(done) break; for(ibyte=0; ibyte<4; ibyte++) { shift = (ibyte*8); mask = (0xFF)<<shift; byte = (hn[i] & mask)>>shift; if(byte==0x0) { done=1; break; } sprintf(byte_c,"%c",byte); strcat(hostname,byte_c); } } if(pFlag) printf("%s: Hostname = >%s<\n", __FUNCTION__,hostname); strcpy((char *)rval,hostname); slen = (int)strlen(hostname); return slen; }
/* Adds something to the payload. The caller must guarrantee that * there is enough space in the payload string to accommodate the * added value. * payload_length and hdr will be modified as a side-effect. * base_offset is the payload offset from the packet's beginning, and is */ void ntlm_add_to_payload(char *payload, int *payload_length, strhdr * hdr, char *toadd, int toadd_length, int base_offset) { int l = (*payload_length); memcpy(payload + l, toadd, toadd_length); hdr->len = SSWAP(toadd_length); hdr->maxlen = SSWAP(toadd_length); hdr->offset = WSWAP(l + base_offset); /* 48 is the base offset of the payload */ (*payload_length) += toadd_length; }
int main(void) { short var = 0x1234; printf("low = %x\n", SLOW(var)); printf("low = %#x\n", SLOW(var)); printf("high = %#x\n", SHIGH(var)); printf("SSWAP = %#x\n", SSWAP(var)); return 0; }
int gtpVMEGetCpuStatus() { int rval=0; if(vGTPp==NULL) { printf("%s: ERROR: GTP not initialized\n",__FUNCTION__); return ERROR; } GTPLOCK; rval = vmeRead32(&vGTPp->CpuStatus[0]); rval = SSWAP(rval) & GTP_CPUSTATUS_BOOTED; GTPUNLOCK; return rval; }
/* fetches a string from the authentication packet. * The lstring data-part points to inside the packet itself. * It's up to the user to memcpy() that if the value needs to * be used in any way that requires a tailing \0. (he can check whether the * value is there though, in that case lstring.length==-1). */ lstring ntlm_fetch_string(char *packet, int32_t length, strhdr * str) { int16_t l; /* length */ int32_t o; /* offset */ lstring rv; lstring_zero(rv); l = SSWAP(str->len); o = WSWAP(str->offset); /* debug("fetch_string(plength=%d,l=%d,o=%d)\n",length,l,o); */ if (l < 0 || o <= 0 || l > MAX_FIELD_LENGTH || o + l > length) { /* debug("ntlmssp: insane data (l: %d, o: %d)\n", l,o); */ return rv; } rv.str = packet + o; rv.l = l; return rv; }
/* input: SystemName output: NrOfSlot - the number of slots NrofChList - the number of channels ModelList - DescriptionList - SerNumList - FmwRelMinList - FmwRelMaxList - */ int CAENHVGetCrateMap(const char *SystemName, unsigned short *NrOfSlot, unsigned short **NrofChList, char **ModelList, char **DescriptionList, unsigned short **SerNumList, unsigned char **FmwRelMinList, unsigned char **FmwRelMaxList) { int id=0; /// my: UINT16 crate=0, code, value[20], buffer[1024]; /// my: int tmp=0; int i, ii; UINT32 addr=0, Vmax; /// my: UINT16 bitmap, Imax, Rampmin, Rampmax, Vres, Ires, Vdec, Idec; unsigned short *u1, *u2; char *bname, Iunits[3]; UINT8 *b8 = (UINT8 *)buffer, *c1, *c2; char *m, *d; float paw_10[] = {1., 10., 100.}; GET_SYSTEM_ID(SystemName); code = 4; /*returns crate occupation (bitmap)*/ V288SENDANDGET; bitmap = buffer[0]; /*printf("v288Get returns %d\n",tmp);*/ *NrOfSlot = 10; /* sy527 has 10 slots */ /*printf("\nCrate bitmap 0x%04x, NrOfSlot=%d\n\n",bitmap,*NrOfSlot);*/ /* allocate memory for output parameters */ *NrofChList = calloc(*NrOfSlot,sizeof(unsigned short)); *SerNumList = calloc(*NrOfSlot,sizeof(unsigned short)); *FmwRelMinList = calloc(*NrOfSlot,sizeof(unsigned char)); *FmwRelMaxList = calloc(*NrOfSlot,sizeof(unsigned char)); *ModelList = calloc((*NrOfSlot)*256,sizeof(char)); *DescriptionList = calloc((*NrOfSlot)*256,sizeof(char)); u1 = *NrofChList; u2 = *SerNumList; c1 = *FmwRelMinList; c2 = *FmwRelMaxList; m = *ModelList; d = *DescriptionList; /* get crate information */ code = 3; for(i=0; i<(*NrOfSlot); i++, m+=strlen(m)+1, d+=strlen(d)+1) { if( !((bitmap>>i)&0x1) ) { strcpy(m,""); continue; /*skip empty slots*/ } /*printf("\n Slot number %d ==================== (bitmap=0x%08x)\n",i,bitmap);*/ value[0] = i; /*slot number(from 0)*/ /* send command and get data */ V288SENDANDGET; /*printf("v288Get returns %d\n",tmp);*/ if(tmp<=0) continue; #ifndef VXWORKS for(ii=0; ii<tmp; ii++) buffer[ii] = SSWAP(buffer[ii]); #endif /* print results for(ii=0; ii<tmp; ii++) printf("[%3d] %5d 0x%04x\n",ii,buffer[ii],buffer[ii]); */ bname = (char *)&buffer[0]; strncpy(m,bname,5); /* max 5 characters */ m[5] = '\0'; /* in case of 5-char name 'm' will not be null-terminated, so do it */ /*printf("Board name: >%5.5s< (len=%d)\n",bname,strlen(m));*/ strcpy(d,"n/a"); tmp = b8[5]; if(tmp==0) strcpy(Iunits,"A "); else if(tmp==1) strcpy(Iunits,"mA"); else if(tmp==2) strcpy(Iunits,"uA"); else if(tmp==3) strcpy(Iunits,"nA"); /*printf("[%2d] Current units: %s\n",i,Iunits);*/ #ifndef VXWORKS buffer[3] = SSWAP(buffer[3]); #endif u2[i] = buffer[3]; /*printf("Serial number %d\n",buffer[3]);*/ c2[i] = b8[8]; c1[i] = b8[9]; /*printf("Software version %2d.%02d\n",b8[8],b8[9]);*/ u1[i] = (unsigned short)b8[30]; /*printf("Num. of Channels %d (%d 0x%08x)\n",b8[30],u1[i],&u1[i]);*/ Vmax = (b8[35]<<24)+(b8[36]<<16)+(b8[37]<<8)+b8[38]; Imax = (b8[39]<<8)+b8[40]; Rampmin = (b8[41]<<8)+b8[42]; Rampmax = (b8[43]<<8)+b8[44]; Vres = (b8[45]<<8)+b8[46]; Ires = (b8[47]<<8)+b8[48]; Vdec = (b8[49]<<8)+b8[50]; Idec = (b8[51]<<8)+b8[52]; sy527[id].scalev[i] = paw_10[Vdec]; sy527[id].scalei[i] = paw_10[Idec]; /* printf("Vmax=%d V\n",Vmax); printf("Imax=%d %s\n",Imax,Iunits); printf("Rampmin=%d V/sec\n",Rampmin); printf("Rampmax=%d V/sec\n",Rampmax); */ /* printf("\n"); printf("[%2d] Vres=%d*0.01 V\n",i,Vres); printf("[%2d] Ires=%d*0.01 %s\n",i,Ires,Iunits); printf("[%2d] Vdec=%d significant figures after the decimal point\n",i,Vdec); printf("[%2d] Idec=%d significant figures after the decimal point\n",i,Idec); printf("\n"); */ } return(CAENHV_OK); }
int BOSrecordSwap(unsigned int *src, unsigned int *dest) { unsigned int lwd; unsigned short swd; int ii, jj, ix, k; int hlen, tlen, blen, dlen, lform, dtype, typ; short shd; char cd; char *cp; unsigned short *sp, *spd; unsigned int *lp, *lpd; unsigned int bankid, banknum, ncol, nrow, lname, lfmt, fmtlen, nwords, bb; char *form; int nevent; /* if 'dest' == NULL, swap 'src' buffer in place */ if(dest == NULL) { dest = src; } /*printf("src=0x%08x dest=0x%08x\n",src,dest);*/ ii = 0; lp = (unsigned int *)&src[ii]; lpd = (unsigned int *)&dest[ii]; blen = *(lp+RECHEADLEN-1); /* last word in record header */ /* printf("\n\n\nFPACK record length = %d\n",blen); */ /* printf("3rd: 0x%08x %d\n",lp[2],lp[2]); lp[2] = 0; */ /* swap record header: RECHEADLEN words */ for(jj=0; jj<RECHEADLEN; jj++) { /* if(jj==5) printf("befor %d 0x%08x\n",*lp,*lp); */ /* do not swap record name */ if((jj==3) || (jj==4)) { *lpd++ = *lp; lp++; continue; } lwd = LSWAP(*lp); /* set endian signature (or automatically ???) */ if(jj==1) { #if defined(Linux) || defined(SunOS_i86pc) lwd = 1*16 + 8; #else lwd = 4*16 + 8; #endif lwd = LSWAP(lwd); } *lpd++ = lwd; lp++; /* if(jj==5) printf("after %d 0x%08x\n",lwd,lwd); */ } ii += RECHEADLEN; /*********************************/ /* loop over all banks in record */ lp = (unsigned int *)&src[ii]; lpd = (unsigned int *)&dest[ii]; bb = 0; while(bb < blen) { hlen = *lp; /* record header length (words) */ dlen = *(lp+8); /* data length (words) */ lname = *(lp+1); /* bank name */ lform = *(lp+9); /* first word of format string */ form = (char *)(lp+9); /* remember the position of format description */ #ifdef SunOS_sun4u /*Sergey: temporary !!!*/ if(lform==B16TAG0) { /*printf("WARN: B16TAG0 correction: befor >%4.4s<, ",form);*/ lform = *(lp+9) = B16TAG; /*printf("after >%4.4s< (bank >%4.4s<) (nev=%d)\n",form,(char *)&lname,nevent);*/ } if(lform==B32TAG0) { /*printf("WARN: B32TAG0 correction: befor >%4.4s<, ",form);*/ lform = *(lp+9) = B32TAG; /*printf("after >%4.4s< (bank >%4.4s<)\n",form,(char *)&lname);*/ } #endif /* printf("\nBANK record length=%d, header length=%d, name >%4.4s", dlen,hlen,&lname); */ /*if(blen==1406)*/ /* { char *ffff = form; printf("\nBANK record length=%d, header length=%d, name >%4.4s<, format >", dlen,hlen,&lname); for(jj=0; jj<(hlen-9); jj++) { printf("%4.4s",ffff); ffff += 4; } printf("<\n"); } */ /* swap BOS bank header; header length is 'hlen' but we will swap 9 first words only, excluding second and third which are bank name; words starting from 10th are format description and they should not be swapped as well */ *lpd++ = LSWAP(*lp); lp++; /* swap first word */ *lpd++ = *lp++; /* copy second word (bank name) */ *lpd++ = *lp++; /* copy third word (bank name) */ *lpd++ = LSWAP(*lp); lp++; *lpd++ = LSWAP(*lp); lp++; *lpd++ = LSWAP(*lp); lp++; *lpd++ = LSWAP(*lp); lp++; *lpd++ = LSWAP(*lp); lp++; *lpd++ = LSWAP(*lp); lp++; for(jj=9; jj<hlen; jj++) *lpd++ = *lp++; /* copy format description */ bb += hlen; if(lform==B16TAG) /* short (look for 'B16 ')*/ { /*printf("B16 >%4.4s< (0x%08x)\n",form,lform);*/ sp = (unsigned short *)lp; spd = (unsigned short *)lpd; for(jj=0; jj<dlen*2; jj++) {*spd++ = SSWAP(*sp); sp++;} lp += dlen; lpd += dlen; } else if(!strncmp(form,"(A)",3)) { /*printf("format >%3.3s<\n",form);*/ for(jj=0; jj<dlen; jj++) *lpd++ = *lp++; } else if(!strncmp(form,"(F,8A)",6)) { /*printf("format >%6.6s< dlen=%d\n",form,dlen);*/ for(jj=0; jj<dlen; jj+=9) { /*printf("value=%f\n",*((float *)lp));*/ {*lpd++ = LSWAP(*lp); lp++;} for(k=0; k<8; k++) *lpd++ = *lp++; } } else if(lform == B32TAG) /* int (look for 'B32 ')*/ { for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;} } else if( (!strncmp(form,"I",1)) || (!strncmp(form,"(I)",3)) ) { if(!strncmp((char *)&lname,"HEAD",4)) { nevent=lp[2]; /*printf("nev=%d\n",nevent);*/ } for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;} } else if( (!strncmp(form,"F",1)) || (!strncmp(form,"(F)",3)) ) { for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;} } else if( (!strncmp(form,"A",1)) || (!strncmp(form,"(A)",3)) ) /* ????? */ { for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;} } /* some special cases - until we have generic algorithm */ else if( (!strncmp(form,"3I,6F",5)) ) { for(jj=0; jj<dlen; jj++) {*lpd++ = LSWAP(*lp); lp++;} } else { printf("ERROR: unsupported format >"); for(jj=0; jj<hlen; jj++) printf("%c",form[jj]); printf("< - copy 'as is'\n"); for(jj=0; jj<dlen; jj++) {*lpd++ = *lp; lp++;} } bb += dlen; } return(0); }
// ntlm auth header username extraction - also lets connection persist long enough to complete NTLM negotiation int ntlminstance::identify(Socket& peercon, Socket& proxycon, HTTPHeader &h, std::string &string) { FDTunnel fdt; Socket* upstreamcon; Socket ntlmcon; String url; if (transparent) { // we are actually sending to a second Squid, which just does NTLM ntlmcon.connect(transparent_ip, transparent_port); upstreamcon = &ntlmcon; url = h.getUrl(); h.makeTransparent(false); } else { upstreamcon = &proxycon; } String at(h.getAuthType()); if (transparent && (at != "NTLM")) { // obey forwarded-for options in what we send out std::string clientip; if (o.forwarded_for == 1) { if (o.use_xforwardedfor == 1) { // grab the X-Forwarded-For IP if available clientip = h.getXForwardedForIP(); // otherwise, grab the IP directly from the client connection if (clientip.length() == 0) clientip = peercon.getPeerIP(); } else { clientip = peercon.getPeerIP(); } h.addXForwardedFor(clientip); // add squid-like entry } // in transparent mode, we need to make the initial auth required response // appear to come from the smoothie itself as an origin server, not as a proxy. // // accomplish this by redirecting to a URL that results in accessing DG as if it was // a webserver, fudging origin-server-style NTLM auth to the client whilst actually // performing proper proxy-style auth to the parent proxy, then redirecting the client // back to the actual URL. if (!url.contains("sgtransntlmdest=")) { // user has not yet been redirected // get the browser to make a request to the proxy port on the relevant interface, // embedding the original URL they were trying to access. // unless they're accessing a domain for which authentication is not required, // in which case return a no match response straight away. if (no_auth_list >= 0) { #ifdef DGDEBUG std::cout << "NTLM: Checking noauthdomains list" << std::endl; #endif std::string::size_type start = url.find("://"); if (start != std::string::npos) { start += 3; std::string domain; domain = url.getHostname(); #ifdef DGDEBUG std::cout << "NTLM: URL " << url << ", domain " << domain << std::endl; #endif char *i; while ((start = domain.find('.')) != std::string::npos) { i = o.lm.l[no_auth_list]->findInList(domain.c_str()); if (i != NULL) { #ifdef DGDEBUG std::cout << "NTLM: Found domain in noauthdomains list" << std::endl; #endif return DGAUTH_NOMATCH; } domain.assign(domain.substr(start + 1)); } if (!domain.empty()) { domain = "." + domain; i = o.lm.l[no_auth_list]->findInList(domain.c_str()); if (i != NULL) { #ifdef DGDEBUG std::cout << "NTLM: Found domain in noauthdomains list" << std::endl; #endif return DGAUTH_NOMATCH; } } } } string = "http://"; string += hostname; string += ":"; string += String(peercon.getPort()).toCharArray(); string += "/?sgtransntlmdest="; string += url.toCharArray(); #ifdef DGDEBUG std::cout << "NTLM - redirecting client to " << string << std::endl; #endif return DGAUTH_REDIRECT; } #ifdef DGDEBUG std::cout << "NTLM - forging initial auth required from origin server" << std::endl; #endif // obey forwarded-for options in what we send out if (o.forwarded_for == 1) { std::string clientip; if (o.use_xforwardedfor == 1) { // grab the X-Forwarded-For IP if available clientip = h.getXForwardedForIP(); // otherwise, grab the IP directly from the client connection if (clientip.length() == 0) clientip = peercon.getPeerIP(); } else { clientip = peercon.getPeerIP(); } h.addXForwardedFor(clientip); // add squid-like entry } // send a variant on the original request (has to be something Squid will route to the outside // world, and that it will require NTLM authentication for) String domain(url.after("?sgtransntlmdest=").after("://")); if (domain.contains("/")) domain = domain.before("/"); domain = "http://" + domain + "/"; h.setURL(domain); h.makePersistent(); h.out(&peercon, upstreamcon, __DGHEADER_SENDALL); // grab the auth required response and make it look like it's from the origin server h.in(upstreamcon, true); h.makeTransparent(true); h.makePersistent(); // send it to the client h.out(NULL, &peercon, __DGHEADER_SENDALL); if (h.contentLength() != -1) fdt.tunnel(*upstreamcon, peercon, false, h.contentLength(), true); if (h.isPersistent()) { // now grab the client's response to the auth request, and carry on as usual. h.in(&peercon, true); h.makeTransparent(false); at = h.getAuthType(); } else return DGAUTH_NOMATCH; } else if (transparent && url.contains("?sgtransntlmdest=")) { // send a variant on the original request (has to be something Squid will route to the outside // world, and that it will require NTLM authentication for) String domain(url.after("?sgtransntlmdest=").after("://")); if (domain.contains("/")) domain = domain.before("/"); domain = "http://" + domain + "/"; h.setURL(domain); } if (at != "NTLM") { // if no auth currently underway, then... if (at.length() == 0) { // allow the initial request through so the client will get the proxy's initial auth required response. // advertise persistent connections so that parent proxy will agree to advertise NTLM support. #ifdef DGDEBUG std::cout << "No auth negotiation currently in progress - making initial request persistent so that proxy will advertise NTLM" << std::endl; #endif h.makePersistent(); } return DGAUTH_NOMATCH; } #ifdef DGDEBUG std::cout << "NTLM - sending step 1" << std::endl; #endif if (o.forwarded_for) { std::string clientip; if (o.use_xforwardedfor) { // grab the X-Forwarded-For IP if available clientip = h.getXForwardedForIP(); // otherwise, grab the IP directly from the client connection if (clientip.length() == 0) clientip = peercon.getPeerIP(); } else { clientip = peercon.getPeerIP(); } h.addXForwardedFor(clientip); // add squid-like entry } h.makePersistent(); h.out(&peercon, upstreamcon, __DGHEADER_SENDALL); #ifdef DGDEBUG std::cout << "NTLM - receiving step 2" << std::endl; #endif h.in(upstreamcon, true); if (h.authRequired()) { #ifdef DGDEBUG std::cout << "NTLM - sending step 2" << std::endl; #endif if (transparent) h.makeTransparent(true); h.out(NULL, &peercon, __DGHEADER_SENDALL); if (h.contentLength() != -1) fdt.tunnel(*upstreamcon, peercon, false, h.contentLength(), true); #ifdef DGDEBUG std::cout << "NTLM - receiving step 3" << std::endl; #endif h.in(&peercon, true); if (transparent) { h.makeTransparent(false); String domain(url.after("?sgtransntlmdest=").after("://")); if (domain.contains("/")) domain = domain.before("/"); domain = "http://" + domain + "/"; h.setURL(domain); } #ifdef DGDEBUG std::cout << "NTLM - decoding type 3 message" << std::endl; #endif std::string message(h.getAuthData()); ntlm_authenticate auth; ntlm_auth *a = &(auth.a); static char username[256]; // fixed size static char username2[256]; char* inptr = username; char* outptr = username2; size_t l,o; // copy the NTLM message into the union's buffer, simultaneously filling in the struct if ((message.length() > sizeof(ntlm_auth)) || (message.length() < offsetof(ntlm_auth, payload))) { syslog(LOG_ERR, "NTLM - Invalid message of length %zd, message was: %s", message.length(), message.c_str()); #ifdef DGDEBUG std::cerr << "NTLM - Invalid message of length " << message.length() << ", message was: " << message << std::endl; #endif return -3; } memcpy((void *)auth.buf, (const void *)message.c_str(), message.length()); // verify that the message is indeed a type 3 if (strcmp("NTLMSSP",a->h.signature) == 0 && WSWAP(a->h.type) == 3) { // grab the length & offset of the username within the message // cope with the possibility we are a different byte order to Windows l = SSWAP(a->user.len); o = WSWAP(a->user.offset); if ((l > 0) && (o >= 0) && (o + l) <= sizeof(a->payload) && (l <= 254)) { // everything is in range // note offsets are from start of packet - not the start of the payload area memcpy((void *)username, (const void *)&(auth.buf[o]),l); username[l] = '\0'; // check flags - we may need to convert from UTF-16 to something more sensible int f = WSWAP(a->flags); if (f & WSWAP(0x0001)) { iconv_t ic = iconv_open("UTF-8", "UTF-16LE"); if (ic == (iconv_t)-1) { syslog(LOG_ERR, "NTLM - Cannot initialise conversion from UTF-16LE to UTF-8: %s", strerror(errno)); #ifdef DGDEBUG std::cerr << "NTLM - Cannot initialise conversion from UTF-16LE to UTF-8: " << strerror(errno) << std::endl; #endif iconv_close(ic); return -2; } size_t l2 = 256; local_iconv_adaptor(iconv, ic, &inptr, &l, &outptr, &l2); iconv_close(ic); username2[256 - l2] = '\0'; #ifdef DGDEBUG std::cout << "NTLM - got username (converted from UTF-16LE) " << username2 << std::endl; #endif string = username2; } else { #ifdef DGDEBUG std::cout << "NTLM - got username " << username << std::endl; #endif string = username; } if (!transparent) return DGAUTH_OK; // if in transparent mode, send a redirect to the client's original requested URL, // having sent the final headers to the NTLM-only Squid to do with what it will std::string tmp = peercon.getPeerIP(); h.addXForwardedFor(tmp); h.out(&peercon, upstreamcon, __DGHEADER_SENDALL); // also, the return code matters in ways it hasn't mattered before: // mustn't send a redirect if it is still 407, or we get a redirection loop h.in(upstreamcon, true); if (h.returnCode() == 407) { h.makeTransparent(false); h.out(NULL, &peercon, __DGHEADER_SENDALL); return -10; } url = url.after("="); string = url.toCharArray(); return DGAUTH_REDIRECT; } } return DGAUTH_NOMATCH; } else { #ifdef DGDEBUG std::cout << "NTLM - step 2 was not part of an auth handshake!" << std::endl; for (unsigned int i = 0; i < h.header.size(); i++) std::cout << h.header[i] << std::endl; #endif syslog(LOG_ERR, "NTLM - step 2 was not part of an auth handshake! (%s)", h.header[0].toCharArray()); return -1; } }
/* gtpInit - Initialize the Global Trigger Processor module */ int gtpVMEInit(int rFlag) { unsigned long tiBase=0, gtpBase=0; unsigned int tmp1, tmp2, BoardId=0, version=0; if(TIp==NULL) { printf("%s: ERROR: TI not initialized\n",__FUNCTION__); return ERROR; } /* Verify that the ctp registers are in the correct space for the TI I2C */ tiBase = (unsigned long)TIp; gtpBase = (unsigned long)&(TIp->SWA[0]); if( (gtpBase-tiBase) != GTPBASE) { printf("%s: ERROR: GTP memory structure not in correct VME Space!\n", __FUNCTION__); printf(" current base = 0x%lx expected base = 0x%lx\n", gtpBase-tiBase, (unsigned long)GTPBASE); return ERROR; } vGTPp = (struct GTPStruct *)(&TIp->SWA[0]); /* Check the module ID, to confirm we've got a GTP in there */ GTPLOCK; tmp1 = vmeRead32(&vGTPp->BoardId[1])&0xFFFF; tmp2 = vmeRead32(&vGTPp->BoardId[0])&0xFFFF; BoardId = SSWAP(tmp1)<<16|SSWAP(tmp2); tmp1 = vmeRead32(&vGTPp->FirmwareRev[1])&0xFFFF; tmp2 = vmeRead32(&vGTPp->FirmwareRev[0])&0xFFFF; version = SSWAP(tmp1)<<16|SSWAP(tmp2); GTPUNLOCK; if(BoardId != (GTP_BOARDID)) { printf("%s: ERROR: Invalid GTP Board ID (0x%08x)\n", __FUNCTION__,BoardId); return ERROR; } if(version == 0xffffffff) { printf("%s: ERROR: Unable to read GTP version (returned 0x%x)\n", __FUNCTION__,version); return ERROR; } printf("%s: GTP (Type %d v%d.%d) initialized at Local Base address 0x%lx\n", __FUNCTION__, (version & GTP_FIRMWAREREV_TYPE_MASK)>>16, (version & GTP_FIRMWAREREV_MAJOR_MASK)>>8, (version & GTP_FIRMWAREREV_MINOR_MASK), gtpBase); return OK; }