PDS SetReplyMode(byte[] buffer, int bufferLength) { byte partition; int i; string comma = "("; if (bufferLength < 5) { telnet.Trace.trace_ds(" error: wrong field length %d\n", bufferLength); return(PDS.BadCommand); } partition = buffer[3]; telnet.Trace.trace_ds("(0x%02x)", partition); if (partition != 0x00) { telnet.Trace.trace_ds(" error: illegal partition\n"); return(PDS.BadCommand); } switch (buffer[4]) { case Codes.Field: telnet.Trace.trace_ds(" Field\n"); break; case Codes.ExtendedField: telnet.Trace.trace_ds(" ExtendedField\n"); break; case Codes.Character: telnet.Trace.trace_ds(" Character"); break; default: telnet.Trace.trace_ds(" unknown mode 0x%02x\n", buffer[4]); return(PDS.BadCommand); } replyMode = buffer[4]; if (buffer[4] == Codes.Character) { telnet.Controller.CrmnAttribute = bufferLength - 5; for (i = 5; i < bufferLength; i++) { telnet.Controller.CrmAttributes[i - 5] = buffer[i]; telnet.Trace.trace_ds("%s%s", comma, See.GetEfaOnly(buffer[i])); comma = ","; } telnet.Trace.trace_ds("%s\n", (telnet.Controller.CrmnAttribute != 0) ? ")" : ""); } return(PDS.OkayNoOutput); }
void DoQueryReplay(NetBuffer obptr, byte code) { int i; string comma = ""; int obptr0 = obptr.Index; int num, denom; if (this.QrInProgress) { this.telnet.Trace.trace_ds("> StructuredField\n"); this.QrInProgress = false; } obptr.Add16(0); obptr.Add(See.SFID_QREPLY); obptr.Add(code); switch (code) { case See.QR_CHARSETS: { this.telnet.Trace.trace_ds("> QueryReply(CharacterSets)\n"); obptr.Add(0x82); /* flags: GE, CGCSGID present */ obptr.Add(0x00); /* more flags */ obptr.Add(7); /* SDW */ obptr.Add(7); /* SDH */ obptr.Add(0x00); /* Load PS format types */ obptr.Add(0x00); obptr.Add(0x00); obptr.Add(0x00); obptr.Add(0x07); /* DL */ obptr.Add(0x00); /* SET 0: */ obptr.Add(0x10); /* FLAGS: non-loadable, single-plane, single-byte, no compare */ obptr.Add(0x00); /* LCID */ obptr.Add32(cgcsgid); /* CGCSGID */ // TODO: Missing font stuff for extended font information break; } case See.QR_IMP_PART: { this.telnet.Trace.trace_ds("> QueryReply(ImplicitPartition)\n"); obptr.Add(0x0); /* reserved */ obptr.Add(0x0); obptr.Add(0x0b); /* length of display size */ obptr.Add(0x01); /* "implicit partition size" */ obptr.Add(0x00); /* reserved */ obptr.Add16(80); /* implicit partition width */ obptr.Add16(24); /* implicit partition height */ obptr.Add16(this.telnet.Controller.MaxColumns); /* alternate height */ obptr.Add16(this.telnet.Controller.MaxRows); /* alternate width */ break; } case See.QR_NULL: { this.telnet.Trace.trace_ds("> QueryReply(Null)\n"); break; } case See.QR_SUMMARY: { this.telnet.Trace.trace_ds("> QueryReply(Summary("); for (i = 0; i < NSR; i++) { this.telnet.Trace.trace_ds("%s%s", comma, See.GetQCodeode(this.SupportedReplies[i])); comma = ","; obptr.Add(this.SupportedReplies[i]); } this.telnet.Trace.trace_ds("))\n"); break; } case See.QR_USABLE_AREA: { this.telnet.Trace.trace_ds("> QueryReply(UsableArea)\n"); obptr.Add(0x01); /* 12/14-bit addressing */ obptr.Add(0x00); /* no special character features */ obptr.Add16(this.telnet.Controller.MaxColumns); /* usable width */ obptr.Add16(this.telnet.Controller.MaxRows); /* usable height */ obptr.Add(0x01); /* units (mm) */ num = 100; denom = 1; while (0 == (num % 2) && 0 == (denom % 2)) { num /= 2; denom /= 2; } obptr.Add16((int)num); /* Xr numerator */ obptr.Add16((int)denom); /* Xr denominator */ num = 100; denom = 1; while (0 == (num % 2) && 0 == (denom % 2)) { num /= 2; denom /= 2; } obptr.Add16((int)num); /* Yr numerator */ obptr.Add16((int)denom); /* Yr denominator */ obptr.Add(7); /* AW */ obptr.Add(7); /* AH */ obptr.Add16(this.telnet.Controller.MaxColumns * this.telnet.Controller.MaxRows); /* buffer, questionable */ break; } case See.QR_COLOR: { this.telnet.Trace.trace_ds("> QueryReply(Color)\n"); obptr.Add(0x00); /* no options */ obptr.Add(this.telnet.Appres.color8 ? 8 : 16); /* report on 8 or 16 colors */ obptr.Add(0x00); /* default color: */ obptr.Add(0xf0 + See.COLOR_GREEN); /* green */ for (i = 0xf1; i <= (this.telnet.Appres.color8 ? 0xf8 : 0xff); i++) { obptr.Add(i); if (this.telnet.Appres.m3279) { obptr.Add(i); } else { obptr.Add(0x00); } } break; } case See.QR_HIGHLIGHTING: { this.telnet.Trace.trace_ds("> QueryReply(Highlighting)\n"); obptr.Add(5); /* report on 5 pairs */ obptr.Add(See.XAH_DEFAULT); /* default: */ obptr.Add(See.XAH_NORMAL); /* normal */ obptr.Add(See.XAH_BLINK); /* blink: */ obptr.Add(See.XAH_BLINK); /* blink */ obptr.Add(See.XAH_REVERSE); /* reverse: */ obptr.Add(See.XAH_REVERSE); /* reverse */ obptr.Add(See.XAH_UNDERSCORE); /* underscore: */ obptr.Add(See.XAH_UNDERSCORE); /* underscore */ obptr.Add(See.XAH_INTENSIFY); /* intensify: */ obptr.Add(See.XAH_INTENSIFY); /* intensify */ break; } case See.QR_REPLY_MODES: { this.telnet.Trace.trace_ds("> QueryReply(ReplyModes)\n"); obptr.Add(Codes.Field); obptr.Add(Codes.ExtendedField); obptr.Add(Codes.Character); break; } case See.QR_ALPHA_PART: { this.telnet.Trace.trace_ds("> QueryReply(AlphanumericPartitions)\n"); obptr.Add(0); /* 1 partition */ obptr.Add16(this.telnet.Controller.MaxRows * this.telnet.Controller.MaxColumns); /* buffer space */ obptr.Add(0); /* no special features */ break; } default: { // Internal error return; } } obptr.Add16At(obptr0, obptr.Index - obptr0); }
PDS ReadPart(byte[] buffer, int bufferLength) { byte partition; int any = 0; string comma = ""; NetBuffer obptr = null; if (bufferLength < 5) { telnet.Trace.trace_ds(" error: field length %d too small\n", bufferLength); return(PDS.BadCommand); } partition = buffer[3]; this.telnet.Trace.trace_ds("(0x%02x)", partition); switch (buffer[4]) { case Codes.Query: { this.telnet.Trace.trace_ds(" Query"); if (partition != 0xff) { this.telnet.Trace.trace_ds(" error: illegal partition\n"); return(PDS.BadCommand); } this.telnet.Trace.trace_ds("\n"); obptr = this.QueryReplyStart(); for (int i = 0; i < NSR; i++) { this.DoQueryReplay(obptr, SupportedReplies[i]); } this.QueryReplyEnd(obptr); break; } case Codes.QueryList: { telnet.Trace.trace_ds(" QueryList "); if (partition != 0xff) { telnet.Trace.trace_ds("error: illegal partition\n"); return(PDS.BadCommand); } if (bufferLength < 6) { telnet.Trace.trace_ds("error: missing request type\n"); return(PDS.BadCommand); } obptr = QueryReplyStart(); switch (buffer[5]) { case Codes.QCodeList: { telnet.Trace.trace_ds("List("); if (bufferLength < 7) { telnet.Trace.trace_ds(")\n"); DoQueryReplay(obptr, See.QR_NULL); } else { for (int i = 6; i < bufferLength; i++) { telnet.Trace.trace_ds("%s%s", comma, See.GetQCodeode(buffer[i])); comma = ","; } this.telnet.Trace.trace_ds(")\n"); for (int i = 0; i < NSR; i++) { bool found = false; for (int pos = 0; pos < bufferLength - 6; pos++) { if (buffer[pos + 6] == this.SupportedReplies[i]) { found = true; } } if (found) { this.DoQueryReplay(obptr, this.SupportedReplies[i]); any++; } } if (any == 0) { this.DoQueryReplay(obptr, See.QR_NULL); } } break; } case Codes.EquivQCodeList: { this.telnet.Trace.trace_ds("Equivlent+List("); for (int i = 6; i < bufferLength; i++) { this.telnet.Trace.trace_ds("%s%s", comma, See.GetQCodeode(buffer[i])); comma = ","; } this.telnet.Trace.trace_ds(")\n"); for (int i = 0; i < NSR; i++) { this.DoQueryReplay(obptr, this.SupportedReplies[i]); } break; } case Codes.All: { this.telnet.Trace.trace_ds("All\n"); for (int i = 0; i < NSR; i++) { this.DoQueryReplay(obptr, this.SupportedReplies[i]); } break; } default: { this.telnet.Trace.trace_ds("unknown request type 0x%02x\n", buffer[5]); return(PDS.BadCommand); } } this.QueryReplyEnd(obptr); break; } case ControllerConstant.SNA_CMD_RMA: { this.telnet.Trace.trace_ds(" ReadModifiedAll"); if (partition != 0x00) { this.telnet.Trace.trace_ds(" error: illegal partition\n"); return(PDS.BadCommand); } this.telnet.Trace.trace_ds("\n"); this.telnet.Controller.ProcessReadModifiedCommand(AID.QReply, true); break; } case ControllerConstant.SNA_CMD_RB: { this.telnet.Trace.trace_ds(" ReadBuffer"); if (partition != 0x00) { this.telnet.Trace.trace_ds(" error: illegal partition\n"); return(PDS.BadCommand); } this.telnet.Trace.trace_ds("\n"); this.telnet.Controller.ProcessReadBufferCommand(AID.QReply); break; } case ControllerConstant.SNA_CMD_RM: { this.telnet.Trace.trace_ds(" ReadModified"); if (partition != 0x00) { this.telnet.Trace.trace_ds(" error: illegal partition\n"); return(PDS.BadCommand); } this.telnet.Trace.trace_ds("\n"); this.telnet.Controller.ProcessReadModifiedCommand(AID.QReply, false); break; } default: { this.telnet.Trace.trace_ds(" unknown type 0x%02x\n", buffer[4]); return(PDS.BadCommand); } } return(PDS.OkayOutput); }
/// <summary> /// Parse the next byte in the client data stream /// </summary> /// <param name="v"></param> public void Parse(byte v) { Console.WriteLine("" + v); switch (cs) { case CS.Waiting: if (v == IAC) { N("IAC"); cs = CS.R_IAC; } else { // assume we're reading a header block header = null; datatype = 0; datapos = 1; data[0] = v; cs = CS.R_HEADER; } break; case CS.R_HEADER: data[datapos] = v; datapos++; if (datapos == TnHeader.EhSize) { header = new TnHeader(data); datapos = 0; cs = CS.R_HEADERDATA; } break; case CS.R_HEADERDATA: data[datapos] = v; if (datapos == 0) { Console.WriteLine(See.GetAidFromCode(v)); } if (datapos == 2) { Console.WriteLine(Util.DecodeBAddress(data[1], data[2])); } if (datapos == 3 && data[3] != ControllerConstant.ORDER_SBA) { throw new ApplicationException("ni"); } else { Console.WriteLine("SBA"); } if (datapos == 5) { int baddr = Util.DecodeBAddress(data[4], data[5]); Console.WriteLine(BA_TO_COL(baddr) + ", " + BA_TO_ROW(baddr)); } if (datapos > 5) { Console.WriteLine(See.GetEbc(Tables.Cg2Ebc[data[datapos]])); } datapos++; break; case CS.R_IAC: if (v == SB) { N("SB"); cs = CS.R_DATA; datatype = v; datapos = 0; } else if (v == WILL) { N("WILL"); cs = CS.R_WILL; } else { NError(v); } break; case CS.R_WILL: Console.WriteLine("will " + v); cs = CS.Waiting; break; case CS.R_DATA: if (v == IAC) { cs = CS.R_IAC_END; } else { data[datapos] = v; datapos++; } break; case CS.R_IAC_END: if (v == IAC) { data[datapos] = v; datapos++; } else { N("IAC"); if (v == SE) { N("SE"); N(data, datapos); cs = CS.Waiting; } else { NError(v); } } break; default: NError(v); break; } }