/* Generated by XDS Modula-2 to ANSI C v4.20 translator */ #define X2C_int32 #define X2C_index32 #ifndef X2C_H_ #include "X2C.h" #endif #define udphub_C_ #ifndef osi_H_ #include "osi.h" #endif #include #ifndef udp_H_ #include "udp.h" #endif #ifndef aprsstr_H_ #include "aprsstr.h" #endif #ifndef Select_H_ #include "Select.h" #endif /* axudp bidirectional digi - user hub by OE5DXL */ #define udphub_CALLLEN 7 #define udphub_MAXLEN 338 #define udphub_MINLEN 17 static uint32_t udphub_POLYNOM = 0x8408UL; static uint32_t udphub_CRCINIT = 0xFFFFUL; #define udphub_SOURCECALL 7 #define udphub_DESTCALL 0 #define udphub_MAXFD 31 #define udphub_cCOM "#" #define udphub_cSPOOF "p" #define udphub_cBCIN "b" #define udphub_cBCOUT "B" #define udphub_cSENDALL "A" #define udphub_LF "\012" #define udphub_TICKER 15 typedef char RAWCALL[7]; struct TIMEVAL { int32_t tvsec; int32_t tvusec; }; struct USER; typedef struct USER * pUSER; struct USER { pUSER next; RAWCALL call; uint32_t uip; uint32_t dport; char datagot; /* not send same data twice to same ip/port */ char bcin; /* broadcast in accept */ char bcout; /* broadcast out allowed */ char willall; /* like host send all to */ char nopurge; /* entry from file no purge */ char nospoof; /* not overwrite ip:port */ char allssid; /* fits with any ssid */ uint32_t htime; uint32_t framesin; uint32_t framesout; }; static uint8_t CRCL[256]; static uint8_t CRCH[256]; static char noinf; static char modified; static char peertopeer; static char defaultbcout; /* no broadcast send to new users */ static char defaultbcin; static char show; /* no broadcast accept for new users */ static char checkdigiip; static pUSER users; /* alllifetime, (* time for all/unknown ssid *) */ static uint32_t systime; static uint32_t lifetime; static uint32_t uptime; static uint32_t touserport; static uint32_t todigiport; static uint32_t digiip; static int32_t digisock; static int32_t usersock; static uint32_t maxentries; static char initfn[1025]; static char wrfn[1025]; static RAWCALL broadcastdest; static uint32_t framecnt; static uint32_t dupecnt; static uint32_t dupewp; static uint32_t maxdupetime; struct _0; struct _0 { uint16_t crc; uint32_t time0; }; static struct _0 dupetab[64]; static void Err(const char text[], uint32_t text_len) { osi_WrStr("udphub: ", 9ul); osi_WrStr(text, text_len); osi_WrStrLn(" error abort", 13ul); X2C_ABORT(); } /* end Err() */ #define udphub_POLINOM 0x8408 static void Gencrctab(void) { uint32_t c; uint32_t crc; uint32_t i; for (c = 0UL; c<=255UL; c++) { crc = 255UL-c; for (i = 0UL; i<=7UL; i++) { if ((crc&1)) crc = (uint32_t)((uint32_t)(crc>>1)^0x8408UL); else crc = crc>>1; } /* end for */ CRCL[c] = (uint8_t)crc; CRCH[c] = (uint8_t)(255UL-(crc>>8)); } /* end for */ } /* end Gencrctab() */ static void WCh(char c) { if (c!='\015') { if ((uint8_t)c<' ' || (uint8_t)c>='\177') osi_WrStr(".", 2ul); else osi_WrStr((char *) &c, 1u/1u); } } /* end WCh() */ static void ShowCall(char f[], uint32_t f_len, uint32_t pos) { uint32_t e; uint32_t i; uint32_t tmp; char tmp0; e = pos; tmp = pos+5UL; i = pos; if (i<=tmp) for (;; i++) { if (f[i]!='@') e = i; if (i==tmp) break; } /* end for */ tmp = e; i = pos; if (i<=tmp) for (;; i++) { WCh((char)((uint32_t)(uint8_t)f[i]>>1)); if (i==tmp) break; } /* end for */ i = (uint32_t)(uint8_t)f[pos+6UL]>>1&15UL; if (i) { osi_WrStr("-", 2ul); if (i>=10UL) { osi_WrStr((char *)(tmp0 = (char)(i/10UL+48UL),&tmp0), 1u/1u); } osi_WrStr((char *)(tmp0 = (char)(i%10UL+48UL),&tmp0), 1u/1u); } } /* end ShowCall() */ static uint32_t udphub_UA = 0x63UL; static uint32_t udphub_DM = 0xFUL; static uint32_t udphub_SABM = 0x2FUL; static uint32_t udphub_DISC = 0x43UL; static uint32_t udphub_FRMR = 0x87UL; static uint32_t udphub_UI = 0x3UL; static uint32_t udphub_RR = 0x1UL; static uint32_t udphub_REJ = 0x9UL; static uint32_t udphub_RNR = 0x5UL; static void Showctl(uint32_t com, uint32_t cmd) { uint32_t cm; char PF[4]; char tmp; osi_WrStr(" ctl ", 6ul); cm = (uint32_t)cmd&~0x10UL; if ((cm&0xFUL)==0x1UL) { osi_WrStr("RR", 3ul); osi_WrStr((char *)(tmp = (char)(48UL+(cmd>>5)),&tmp), 1u/1u); } else if ((cm&0xFUL)==0x5UL) { osi_WrStr("RNR", 4ul); osi_WrStr((char *)(tmp = (char)(48UL+(cmd>>5)),&tmp), 1u/1u); } else if ((cm&0xFUL)==0x9UL) { osi_WrStr("REJ", 4ul); osi_WrStr((char *)(tmp = (char)(48UL+(cmd>>5)),&tmp), 1u/1u); } else if ((cm&0x1UL)==0UL) { osi_WrStr("I", 2ul); osi_WrStr((char *)(tmp = (char)(48UL+(cmd>>5)),&tmp), 1u/1u); osi_WrStr((char *)(tmp = (char)(48UL+(cmd>>1&7UL)),&tmp), 1u/1u); } else if (cm==0x3UL) osi_WrStr("UI", 3ul); else if (cm==0xFUL) osi_WrStr("DM", 3ul); else if (cm==0x2FUL) osi_WrStr("SABM", 5ul); else if (cm==0x43UL) osi_WrStr("DISC", 5ul); else if (cm==0x63UL) osi_WrStr("UA", 3ul); else if (cm==0x87UL) osi_WrStr("FRMR", 5ul); else osi_WrHex(cmd, 1UL); strncpy(PF,"v^-+",4u); if (com==0UL || com==3UL) osi_WrStr("v1", 3ul); else { osi_WrStr((char *) &PF[(com&1UL)+2UL*(uint32_t) ((0x10UL & (uint32_t)cmd)!=0)], 1u/1u); } } /* end Showctl() */ static void ShowFrame(char f[], uint32_t f_len, uint32_t len, char noinfo) { uint32_t i; char d; char v; i = 0UL; while (!((uint32_t)(uint8_t)f[i]&1)) { ++i; if (i>len) return; } /* no address end mark found */ if (i%7UL!=6UL) return; /* address end not modulo 7 error */ osi_WrStr(" fm ", 5ul); ShowCall(f, f_len, 7UL); osi_WrStr(" to ", 5ul); ShowCall(f, f_len, 0UL); i = 14UL; v = 1; while (i+6UL=128UL && (((uint32_t)(uint8_t) f[i+6UL]&1) || (uint32_t)(uint8_t)f[i+13UL]<128UL)) { osi_WrStr("*", 2ul); } i += 7UL; } Showctl((uint32_t)((0x80U & (uint8_t)(uint8_t)f[6UL])!=0) +2UL*(uint32_t)((0x80U & (uint8_t)(uint8_t)f[13UL])!=0) , (uint32_t)(uint8_t)f[i]); ++i; if (i='0' && (uint8_t)h[p]<='9') { ok0 = 1; n = (n*10UL+(uint32_t)(uint8_t)h[p])-48UL; ++p; } if (!ok0) { GetIp1_ret = -1L; goto label; } if (i<3UL) { if (h[p]!='.' || n>255UL) { GetIp1_ret = -1L; goto label; } *ip = *ip*256UL+n; } else if (i==3UL) { *ip = *ip*256UL+n; if (h[p]!=':' || n>255UL) { GetIp1_ret = -1L; goto label; } } else if (n>65535UL) { GetIp1_ret = -1L; goto label; } *port = n; ++p; } /* end for */ GetIp1_ret = 0L; label:; X2C_PFREE(h); return GetIp1_ret; } /* end GetIp1() */ static int32_t getudp(int32_t fd, char buf[], uint32_t buf_len, uint32_t * fromip0, uint32_t * fromport, char checkip) { uint32_t ip; int32_t len; len = udpreceive(fd, buf, (int32_t)(buf_len), fromport, &ip); if (len<2L || !testCRC(buf, buf_len, len)) { if (show) osi_WrStrLn(" axudp crc error ", 18ul); return -1L; } if (checkip && *fromip0!=ip) return -2L; *fromip0 = ip; return len; } /* end getudp() */ static char Call2Str(const char r[], uint32_t r_len, char t[], uint32_t t_len, uint32_t pos, uint32_t * len, char zerossid) { uint32_t ssid; uint32_t e; uint32_t i; char c; uint32_t tmp; e = pos; tmp = pos+5UL; i = pos; if (i<=tmp) for (;; i++) { if (r[i]!='@') e = i; if (i==tmp) break; } /* end for */ tmp = e; i = pos; if (i<=tmp) for (;; i++) { c = (char)((uint32_t)(uint8_t)r[i]>>1); if ((uint8_t)c<=' ') { t[*len] = 0; *len = 0UL; return 0; } t[*len] = c; ++*len; if (i==tmp) break; } /* end for */ ssid = (uint32_t)(uint8_t)r[pos+6UL]>>1&15UL; if (zerossid || ssid>0UL) { t[*len] = '-'; ++*len; if (ssid>9UL) { t[*len] = '1'; ++*len; } t[*len] = (char)(ssid%10UL+48UL); ++*len; } return 1; } /* end Call2Str() */ #define udphub_SSID "-" static char Str2Call(char s[], uint32_t s_len, uint32_t * i, uint32_t p, char cb[], uint32_t cb_len, char * hasssid) { uint32_t j; char Str2Call_ret; X2C_PCOPY((void **)&s,s_len); *hasssid = 0; j = p; while ((*i<=s_len-1 && (uint8_t)s[*i]>' ') && s[*i]!='-') { if (j='0' && (uint8_t)s[*i]<='9') { j = (uint32_t)(uint8_t)s[*i]-48UL; ++*i; } if ((uint8_t)s[*i]>='0' && (uint8_t)s[*i]<='9') { j = (j*10UL+(uint32_t)(uint8_t)s[*i])-48UL; ++*i; } } cb[p+6UL] = (char)(j*2UL+1UL); /* ssid */ Str2Call_ret = j<=15UL; X2C_PFREE(s); return Str2Call_ret; } /* end Str2Call() */ static int32_t GetIp(char h[], uint32_t h_len, uint32_t * ip, uint32_t * dp, uint32_t * lp, int32_t * fd, char * check) { int32_t GetIp_ret; X2C_PCOPY((void **)&h,h_len); if (aprsstr_GetIp2(h, h_len, ip, dp, lp, check)<0L) { GetIp_ret = -1L; goto label; } *fd = openudp(); if (*fd<0L || bindudp(*fd, *lp)<0L) { /*OR (udp.udpnonblock(fd)<0)*/ GetIp_ret = -1L; goto label; } GetIp_ret = 0L; label:; X2C_PFREE(h); return GetIp_ret; } /* end GetIp() */ static char GetNum(const char h[], uint32_t h_len, uint32_t * n) { uint32_t i; *n = 0UL; i = 0UL; while ((uint8_t)h[i]>='0' && (uint8_t)h[i]<='9') { *n = ( *n*10UL+(uint32_t)(uint8_t)h[i])-48UL; ++i; } return h[i]==0; } /* end GetNum() */ static void parms(void) { char ssid; char err0; char h[1024]; uint32_t i; uint32_t fromdigiport; err0 = 0; for (;;) { osi_NextArg(h, 1024ul); if (h[0U]==0) break; if ((h[0U]=='-' && h[1U]) && h[2U]==0) { if (h[1U]=='l') { osi_NextArg(h, 1024ul); if (!GetNum(h, 1024ul, &i)) Err("-l minutes", 11ul); lifetime = i*60UL; } else if (h[1U]=='a') { /* ELSIF h[1]="L" THEN NextArg(h); IF NOT GetNum(h, i) THEN Err("-L minutes") END; alllifetime:=i*60; */ peertopeer = 1; } else if (h[1U]=='I') defaultbcin = 1; else if (h[1U]=='O') defaultbcout = 1; else if (h[1U]=='b') { osi_NextArg(h, 1024ul); if (h[0U]==0) Err("-b call", 8ul); i = 0UL; if (!Str2Call(h, 1024ul, &i, 0UL, broadcastdest, 7ul, &ssid)) { Err("-b wrong SSID", 14ul); } } else if (h[1U]=='i') { /* init filename */ osi_NextArg(initfn, 1025ul); } else if (h[1U]=='w') { /* write table filename */ osi_NextArg(wrfn, 1025ul); } else if (h[1U]=='m') { osi_NextArg(h, 1024ul); if (!GetNum(h, 1024ul, &maxentries)) Err("-m number", 10ul); } else if (h[1U]=='p') { osi_NextArg(h, 1024ul); if (!GetNum(h, 1024ul, &touserport)) Err("-p portnumber", 14ul); } else if (h[1U]=='u') { osi_NextArg(h, 1024ul); if (GetIp(h, 1024ul, &digiip, &todigiport, &fromdigiport, &digisock, &checkdigiip)<0L) { Err("cannot open digi udp socket", 28ul); } } else if (h[1U]=='d') { osi_NextArg(h, 1024ul); if (!GetNum(h, 1024ul, &maxdupetime)) { Err("-d maxdupetime", 15ul); } } else if (h[1U]=='v') show = 1; else if (h[1U]=='V') { show = 1; noinf = 0; } else { if (h[1U]=='h') { osic_WrLn(); osi_WrStrLn(" -a route user-to-\ digi AND user-to-user", 71ul); osi_WrStrLn(" -b broadcast dest\ ination call", 62ul); osi_WrStrLn(" -d dupefilter, in\ milliseconds intervall discard frames with same CRC", 102ul); osi_WrStrLn(" -h this", 40ul); osi_WrStrLn(" -I for new user: \ broadcast INPUT on", 68ul); osi_WrStrLn(" -i init routes fr\ om file", 57ul); /* WrStrLn(" -L