ReactOS 0.4.15-dev-6056-gb29b268
conmgr.c File Reference
#include "sacdrv.h"
#include <initguid.h>
Include dependency graph for conmgr.c:

Go to the source code of this file.

Functions

 DEFINE_GUID (PRIMARY_SAC_CHANNEL_APPLICATION_GUID, 0x63D02270, 0x8AA4, 0x11D5, 0xBC, 0xCF, 0x80, 0x6D, 0x61, 0x72, 0x69, 0x6F)
 
VOID NTAPI SacPutString (IN PWCHAR String)
 
BOOLEAN NTAPI SacPutSimpleMessage (IN ULONG MessageIndex)
 
NTSTATUS NTAPI ConMgrDisplayCurrentChannel (VOID)
 
NTSTATUS NTAPI ConMgrWriteData (IN PSAC_CHANNEL Channel, IN PVOID Buffer, IN ULONG BufferLength)
 
NTSTATUS NTAPI ConMgrFlushData (IN PSAC_CHANNEL Channel)
 
BOOLEAN NTAPI ConMgrIsSacChannel (IN PSAC_CHANNEL Channel)
 
BOOLEAN NTAPI ConMgrIsWriteEnabled (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI ConMgrInitialize (VOID)
 
VOID NTAPI ConMgrEventMessage (IN PWCHAR EventMessage, IN BOOLEAN LockHeld)
 
BOOLEAN NTAPI ConMgrSimpleEventMessage (IN ULONG MessageIndex, IN BOOLEAN LockHeld)
 
NTSTATUS NTAPI ConMgrDisplayFastChannelSwitchingInterface (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI ConMgrSetCurrentChannel (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI ConMgrResetCurrentChannel (IN BOOLEAN KeepChannel)
 
NTSTATUS NTAPI ConMgrChannelClose (IN PSAC_CHANNEL Channel)
 
NTSTATUS NTAPI ConMgrShutdown (VOID)
 
NTSTATUS NTAPI ConMgrAdvanceCurrentChannel (VOID)
 
NTSTATUS NTAPI ConMgrChannelOWrite (IN PSAC_CHANNEL Channel, IN PVOID WriteBuffer)
 
VOID NTAPI ConMgrProcessInputLine (VOID)
 
VOID NTAPI ConMgrSerialPortConsumer (VOID)
 
VOID NTAPI ConMgrWorkerProcessEvents (IN PSAC_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI ConMgrGetChannelCloseMessage (IN PSAC_CHANNEL Channel, IN NTSTATUS CloseStatus, OUT PWCHAR OutputBuffer)
 
NTSTATUS NTAPI ConMgrHandleEvent (IN ULONG EventCode, IN PSAC_CHANNEL Channel, OUT PVOID Data)
 

Variables

LONG CurrentChannelRefCount
 
KMUTEX CurrentChannelLock
 
PSAC_CHANNEL CurrentChannel
 
PSAC_CHANNEL SacChannel
 
ULONG ExecutePostConsumerCommand
 
PSAC_CHANNEL ExecutePostConsumerCommandData
 
BOOLEAN InputInEscape
 
BOOLEAN InputInEscTab
 
BOOLEAN ConMgrLastCharWasCR
 
CHAR InputBuffer [80]
 
BOOLEAN GlobalPagingNeeded
 
BOOLEAN GlobalDoThreads
 

Function Documentation

◆ ConMgrAdvanceCurrentChannel()

NTSTATUS NTAPI ConMgrAdvanceCurrentChannel ( VOID  )

Definition at line 410 of file conmgr.c.

411{
413 ULONG Index;
414 PSAC_CHANNEL Channel;
415
416 /* Should always be called with the lock held */
418
419 /* Get the next active channel */
421 if (NT_SUCCESS(Status))
422 {
423 /* Set it as the new channel */
425 if (NT_SUCCESS(Status))
426 {
427 /* Let the user switch to it */
429 }
430 }
431
432 /* All done */
433 return Status;
434}
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ChanMgrGetNextActiveChannel(IN PSAC_CHANNEL CurrentChannel, IN PULONG TargetIndex, OUT PSAC_CHANNEL *TargetChannel)
Definition: chanmgr.c:521
PSAC_CHANNEL CurrentChannel
Definition: conmgr.c:26
NTSTATUS NTAPI ConMgrSetCurrentChannel(IN PSAC_CHANNEL Channel)
Definition: conmgr.c:287
NTSTATUS NTAPI ConMgrDisplayFastChannelSwitchingInterface(IN PSAC_CHANNEL Channel)
Definition: conmgr.c:278
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
FORCEINLINE VOID SacAssertMutexLockHeld(VOID)
Definition: sacdrv.h:1286
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by ConMgrSerialPortConsumer().

◆ ConMgrChannelClose()

NTSTATUS NTAPI ConMgrChannelClose ( IN PSAC_CHANNEL  Channel)

Definition at line 354 of file conmgr.c.

355{
357
358 /* Check if we're in the right channel */
359 if (ConMgrIsWriteEnabled(Channel))
360 {
361 /* Yep, reset it */
364 }
365
366 /* All done */
367 return Status;
368}
NTSTATUS NTAPI ConMgrResetCurrentChannel(IN BOOLEAN KeepChannel)
Definition: conmgr.c:317
BOOLEAN NTAPI ConMgrIsWriteEnabled(IN PSAC_CHANNEL Channel)
Definition: conmgr.c:155
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ ConMgrChannelOWrite()

NTSTATUS NTAPI ConMgrChannelOWrite ( IN PSAC_CHANNEL  Channel,
IN PVOID  WriteBuffer 
)

Definition at line 438 of file conmgr.c.

440{
442
443 /* Do the write with the lock held */
445 ASSERT(FALSE);
446 Status = STATUS_NOT_IMPLEMENTED;// ChannelOWrite(Channel, WriteBuffer + 24, *(WriteBuffer + 20));
448
449 /* Return back to the caller */
451 return Status;
452}
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
FORCEINLINE VOID SacAcquireMutexLock(VOID)
Definition: sacdrv.h:1308
FORCEINLINE VOID SacReleaseMutexLock(VOID)
Definition: sacdrv.h:1320
#define STATUS_NOT_FOUND
Definition: shellext.h:72

◆ ConMgrDisplayCurrentChannel()

NTSTATUS NTAPI ConMgrDisplayCurrentChannel ( VOID  )

Definition at line 81 of file conmgr.c.

82{
84 BOOLEAN HasRedraw;
85
86 /* Make sure the lock is held */
88
89 /* Check if we can redraw */
91 if (NT_SUCCESS(Status))
92 {
93 /* Enable writes */
95 if (HasRedraw)
96 {
97 /* If we can redraw, set the event */
99 }
100
101 /* Flush the output */
103 }
104
105 /* All done, return the status */
106 return Status;
107}
unsigned char BOOLEAN
NTSTATUS NTAPI ChannelOFlush(IN PSAC_CHANNEL Channel)
Definition: channel.c:103
NTSTATUS NTAPI ChannelHasRedrawEvent(IN PSAC_CHANNEL Channel, OUT PBOOLEAN Present)
Definition: channel.c:209
NTSTATUS NTAPI ChannelSetRedrawEvent(IN PSAC_CHANNEL Channel)
Definition: channel.c:176
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)
LONG WriteEnabled
Definition: sacdrv.h:447

Referenced by ConMgrInitialize(), ConMgrResetCurrentChannel(), and ConMgrSerialPortConsumer().

◆ ConMgrDisplayFastChannelSwitchingInterface()

NTSTATUS NTAPI ConMgrDisplayFastChannelSwitchingInterface ( IN PSAC_CHANNEL  Channel)

Definition at line 278 of file conmgr.c.

279{
280 /* FIXME: TODO */
281 ASSERT(FALSE);
283}

Referenced by ConMgrAdvanceCurrentChannel(), and ConMgrResetCurrentChannel().

◆ ConMgrEventMessage()

VOID NTAPI ConMgrEventMessage ( IN PWCHAR  EventMessage,
IN BOOLEAN  LockHeld 
)

Definition at line 235 of file conmgr.c.

237{
238 /* Acquire the current channel lock if needed */
239 if (!LockHeld) SacAcquireMutexLock();
240
241 /* Send out the event message */
243 SacPutString(EventMessage);
245
246 /* Release the current channel lock if needed */
247 if (!LockHeld) SacReleaseMutexLock();
248}
VOID NTAPI SacPutString(IN PWCHAR String)
Definition: conmgr.c:41
BOOLEAN NTAPI SacPutSimpleMessage(IN ULONG MessageIndex)
Definition: conmgr.c:57

Referenced by ConMgrSimpleEventMessage().

◆ ConMgrFlushData()

NTSTATUS NTAPI ConMgrFlushData ( IN PSAC_CHANNEL  Channel)

Definition at line 139 of file conmgr.c.

140{
141 /* Nothing to do */
142 return STATUS_SUCCESS;
143}

Referenced by RawChannelOEcho(), RawChannelOFlush(), VTUTF8ChannelAnsiDispatch(), VTUTF8ChannelOEcho(), and VTUTF8ChannelOFlush().

◆ ConMgrGetChannelCloseMessage()

NTSTATUS NTAPI ConMgrGetChannelCloseMessage ( IN PSAC_CHANNEL  Channel,
IN NTSTATUS  CloseStatus,
OUT PWCHAR  OutputBuffer 
)

Definition at line 878 of file conmgr.c.

881{
882 ASSERT(FALSE);
884}

◆ ConMgrHandleEvent()

NTSTATUS NTAPI ConMgrHandleEvent ( IN ULONG  EventCode,
IN PSAC_CHANNEL  Channel,
OUT PVOID  Data 
)

Definition at line 888 of file conmgr.c.

891{
892 ASSERT(FALSE);
894}

Referenced by ChanMgrCloseChannel().

◆ ConMgrInitialize()

NTSTATUS NTAPI ConMgrInitialize ( VOID  )

Definition at line 163 of file conmgr.c.

164{
165 PWCHAR pcwch;
166 PSAC_CHANNEL FoundChannel;
167 SAC_CHANNEL_ATTRIBUTES SacChannelAttributes;
169
170 /* Initialize the connection manager lock */
173
174 /* Setup the attributes for the raw SAC channel */
175 RtlZeroMemory(&SacChannelAttributes, sizeof(SacChannelAttributes));
176 SacChannelAttributes.ChannelType = VtUtf8;
177
178 /* Get the right name for it */
179 pcwch = GetMessage(SAC_CHANNEL_NAME);
180 ASSERT(pcwch);
181 wcsncpy(SacChannelAttributes.NameBuffer, pcwch, SAC_CHANNEL_NAME_SIZE);
182 SacChannelAttributes.NameBuffer[SAC_CHANNEL_NAME_SIZE] = ANSI_NULL;
183
184 /* Get the right description for it */
185 pcwch = GetMessage(SAC_CHANNEL_DESCRIPTION);
186 ASSERT(pcwch);
187 wcsncpy(SacChannelAttributes.DescriptionBuffer, pcwch, SAC_CHANNEL_DESCRIPTION_SIZE);
189
190 /* Set all the right flags */
192 SacChannelAttributes.CloseEvent = NULL;
193 SacChannelAttributes.HasNewDataEvent = NULL;
194 SacChannelAttributes.LockEvent = NULL;
195 SacChannelAttributes.RedrawEvent = NULL;
196 SacChannelAttributes.ChannelId = PRIMARY_SAC_CHANNEL_APPLICATION_GUID;
197
198 /* Now create it */
199 Status = ChanMgrCreateChannel(&SacChannel, &SacChannelAttributes);
200 if (NT_SUCCESS(Status))
201 {
202 /* Try to get it back */
204 if (NT_SUCCESS(Status))
205 {
206 /* Set it as the current and SAC channel */
207 SacChannel = CurrentChannel = FoundChannel;
208
209 /* Disable writes for now and clear the display */
210 _InterlockedExchange(&FoundChannel->WriteEnabled, FALSE);
212 if (!NT_SUCCESS(Status))
213 {
214 SAC_DBG(SAC_DBG_INIT, "SAC ConMgrInitialize: Failed dispatch\n");
215 }
216
217 /* Display the initial prompt */
218 SacPutSimpleMessage(SAC_NEWLINE);
219 SacPutSimpleMessage(SAC_INIT_STATUS);
220 SacPutSimpleMessage(SAC_NEWLINE);
221 SacPutSimpleMessage(SAC_PROMPT);
222
223 /* Display the current channel */
225 }
226 }
227
228 /* Release the channel lock */
230 return STATUS_SUCCESS;
231}
NTSTATUS NTAPI ChanMgrCreateChannel(OUT PSAC_CHANNEL *Channel, IN PSAC_CHANNEL_ATTRIBUTES Attributes)
Definition: chanmgr.c:345
NTSTATUS NTAPI ChanMgrGetByHandle(IN SAC_CHANNEL_ID ChannelId, OUT PSAC_CHANNEL *TargetChannel)
Definition: chanmgr.c:202
PSAC_CHANNEL SacChannel
Definition: conmgr.c:27
NTSTATUS NTAPI ConMgrDisplayCurrentChannel(VOID)
Definition: conmgr.c:81
#define NULL
Definition: types.h:112
@ HeadlessCmdClearDisplay
Definition: hdl.h:132
NTSTATUS NTAPI HeadlessDispatch(IN HEADLESS_CMD Command, IN PVOID InputBuffer, IN SIZE_T InputBufferSize, OUT PVOID OutputBuffer, OUT PSIZE_T OutputBufferSize)
Definition: hdlsterm.c:570
#define ANSI_NULL
#define SAC_CHANNEL_DESCRIPTION_SIZE
Definition: sacdrv.h:153
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
#define SAC_CHANNEL_NAME_SIZE
Definition: sacdrv.h:152
@ VtUtf8
Definition: sacdrv.h:277
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define SAC_CHANNEL_FLAG_INTERNAL
Definition: sacdrv.h:169
FORCEINLINE VOID SacInitializeMutexLock(VOID)
Definition: sacdrv.h:1297
#define SAC_CHANNEL_FLAG_APPLICATION
Definition: sacdrv.h:174
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
SAC_CHANNEL_TYPE ChannelType
Definition: sacdrv.h:478
WCHAR DescriptionBuffer[SAC_CHANNEL_DESCRIPTION_SIZE+1]
Definition: sacdrv.h:480
WCHAR NameBuffer[SAC_CHANNEL_NAME_SIZE+1]
Definition: sacdrv.h:479
SAC_CHANNEL_ID ChannelId
Definition: sacdrv.h:427
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint16_t * PWCHAR
Definition: typedefs.h:56
#define GetMessage
Definition: winuser.h:5780

Referenced by InitializeDeviceData().

◆ ConMgrIsSacChannel()

BOOLEAN NTAPI ConMgrIsSacChannel ( IN PSAC_CHANNEL  Channel)

Definition at line 147 of file conmgr.c.

148{
149 /* Check which channel is active */
150 return Channel == SacChannel;
151}

◆ ConMgrIsWriteEnabled()

BOOLEAN NTAPI ConMgrIsWriteEnabled ( IN PSAC_CHANNEL  Channel)

Definition at line 155 of file conmgr.c.

156{
157 /* If the current channel is active, allow writes */
158 return ChannelIsEqual(Channel, &CurrentChannel->ChannelId);
159}
BOOLEAN NTAPI ChannelIsEqual(IN PSAC_CHANNEL Channel, IN PSAC_CHANNEL_ID ChannelId)
Definition: channel.c:25

Referenced by ConMgrChannelClose(), RawChannelOWrite(), and VTUTF8ChannelOWrite().

◆ ConMgrProcessInputLine()

VOID NTAPI ConMgrProcessInputLine ( VOID  )

Definition at line 456 of file conmgr.c.

457{
458 BOOLEAN EnablePaging;
460
461 SAC_DBG(SAC_DBG_INIT, "SAC Input Test: %s\n", InputBuffer);
462
463 if (!strncmp(InputBuffer, "t", 1))
464 {
466 }
467 else if (!strncmp(InputBuffer, "?", 1))
468 {
470 }
471 else if (!strncmp(InputBuffer, "help", 4))
472 {
474 }
475 else if (!strncmp(InputBuffer, "f", 1))
476 {
478 }
479 else if (!strncmp(InputBuffer, "p", 1))
480 {
482 }
483 else if (!strncmp(InputBuffer, "id", 2))
484 {
486 }
487 else if (!strncmp(InputBuffer, "crashdump", 9))
488 {
490 }
491 else if (!strncmp(InputBuffer, "lock", 4))
492 {
494 }
495 else if (!strncmp(InputBuffer, "shutdown", 8))
496 {
498 }
499 else if (!strncmp(InputBuffer, "restart", 7))
500 {
502 }
503 else if (!strncmp(InputBuffer, "d", 1))
504 {
505 EnablePaging = GlobalPagingNeeded;
507 &EnablePaging,
508 sizeof(EnablePaging),
509 NULL,
510 NULL);
511 if (!NT_SUCCESS(Status)) SAC_DBG(SAC_DBG_INIT, "SAC Display Log failed.\n");
512 }
513 else if (!strncmp(InputBuffer, "cmd", 3))
514 {
516 {
518 }
519 else
520 {
522 }
523 }
524 else if (!(strncmp(InputBuffer, "ch", 2)) &&
525 (((strlen(InputBuffer) > 1) && (InputBuffer[2] == ' ')) ||
526 (strlen(InputBuffer) == 2)))
527 {
529 }
530 else if (!(strncmp(InputBuffer, "k", 1)) &&
531 (((strlen(InputBuffer) > 1) && (InputBuffer[1] == ' ')) ||
532 (strlen(InputBuffer) == 1)))
533 {
535 }
536 else if (!(strncmp(InputBuffer, "l", 1)) &&
537 (((strlen(InputBuffer) > 1) && (InputBuffer[1] == ' ')) ||
538 (strlen(InputBuffer) == 1)))
539 {
541 }
542 else if (!(strncmp(InputBuffer, "r", 1)) &&
543 (((strlen(InputBuffer) > 1) && (InputBuffer[1] == ' ')) ||
544 (strlen(InputBuffer) == 1)))
545 {
547 }
548 else if (!(strncmp(InputBuffer, "m", 1)) &&
549 (((strlen(InputBuffer) > 1) && (InputBuffer[1] == ' ')) ||
550 (strlen(InputBuffer) == 1)))
551 {
553 }
554 else if (!(strncmp(InputBuffer, "s", 1)) &&
555 (((strlen(InputBuffer) > 1) && (InputBuffer[1] == ' ')) ||
556 (strlen(InputBuffer) == 1)))
557 {
559 }
560 else if (!(strncmp(InputBuffer, "i", 1)) &&
561 (((strlen(InputBuffer) > 1) && (InputBuffer[1] == ' ')) ||
562 (strlen(InputBuffer) == 1)))
563 {
565 }
566 else if ((InputBuffer[0] != '\n') && (InputBuffer[0] != ANSI_NULL))
567 {
568 SacPutSimpleMessage(SAC_UNKNOWN_COMMAND);
569 }
570}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
VOID NTAPI DoRaisePriorityCommand(IN PCHAR PrioString)
Definition: concmd.c:452
VOID NTAPI DoChannelCommand(IN PCHAR ChannelString)
Definition: concmd.c:484
VOID NTAPI DoCrashCommand(VOID)
Definition: concmd.c:466
VOID NTAPI DoLimitMemoryCommand(IN PCHAR LimitString)
Definition: concmd.c:459
VOID NTAPI DoLockCommand(VOID)
Definition: concmd.c:498
VOID NTAPI DoMachineInformationCommand(VOID)
Definition: concmd.c:477
VOID NTAPI DoFullInfoCommand(VOID)
Definition: concmd.c:409
VOID NTAPI DoSetIpAddressCommand(IN PCHAR IpString)
Definition: concmd.c:564
VOID NTAPI DoTlistCommand(VOID)
Definition: concmd.c:571
VOID NTAPI DoSetTimeCommand(IN PCHAR InputTime)
Definition: concmd.c:431
VOID NTAPI DoLowerPriorityCommand(IN PCHAR PrioString)
Definition: concmd.c:445
VOID NTAPI DoCmdCommand(IN PCHAR InputString)
Definition: concmd.c:491
VOID NTAPI DoPagingCommand(VOID)
Definition: concmd.c:420
VOID NTAPI DoHelpCommand(VOID)
Definition: concmd.c:529
VOID NTAPI DoKillCommand(IN PCHAR KillString)
Definition: concmd.c:438
BOOLEAN GlobalPagingNeeded
Definition: conmgr.c:35
ULONG ExecutePostConsumerCommand
Definition: conmgr.c:29
BOOLEAN CommandConsoleLaunchingEnabled
Definition: data.c:16
@ HeadlessCmdDisplayLog
Definition: hdl.h:146
@ Restart
Definition: sacdrv.h:269
@ Shutdown
Definition: sacdrv.h:267
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953

Referenced by ConMgrSerialPortConsumer().

◆ ConMgrResetCurrentChannel()

NTSTATUS NTAPI ConMgrResetCurrentChannel ( IN BOOLEAN  KeepChannel)

Definition at line 317 of file conmgr.c.

318{
320 PSAC_CHANNEL Channel;
321
322 /* Make sure the lock is held */
324
325 /* Get the current SAC channel */
327 if (NT_SUCCESS(Status))
328 {
329 /* Set this as the current SAC channel*/
330 SacChannel = Channel;
332 if (NT_SUCCESS(Status))
333 {
334 /* Check if the caller wants to switch or not */
335 if (KeepChannel)
336 {
337 /* Nope, keep the same channel */
339 }
340 else
341 {
342 /* Yep, show the switching interface */
344 }
345 }
346 }
347
348 /* All done */
349 return Status;
350}

Referenced by ConMgrChannelClose(), and ConMgrSerialPortConsumer().

◆ ConMgrSerialPortConsumer()

VOID NTAPI ConMgrSerialPortConsumer ( VOID  )

Definition at line 574 of file conmgr.c.

575{
577 CHAR Char;
578 WCHAR LastChar;
579 CHAR ReadBuffer[2];
580 ULONG ReadBufferSize, i;
582 SAC_DBG(SAC_DBG_MACHINE, "SAC TimerDpcRoutine: Entering.\n"); //bug
583
584 /* Acquire the manager lock and make sure a channel is selected */
587
588 /* Read whatever came off the serial port */
589 for (Status = SerialBufferGetChar(&Char);
592 {
593 /* If nothing came through, bail out */
594 if (Status == STATUS_NO_DATA_DETECTED) break;
595
596 /* Check if ESC was pressed */
597 if (Char == '\x1B')
598 {
599 /* Was it already pressed? */
600 if (!InputInEscape)
601 {
602 /* First time ESC is pressed! Remember and reset TAB state */
605 continue;
606 }
607 }
608 else if (Char == '\t')
609 {
610 /* TAB was pressed, is it following ESC (VT-100 sequence)? */
611 if (InputInEscape)
612 {
613 /* Yes! This must be the only ESC-TAB we see in once moment */
615
616 /* No longer treat us as being in ESC */
618
619 /* ESC-TAB is the sequence for changing channels */
621 if (!NT_SUCCESS(Status)) break;
622
623 /* Remember ESC-TAB was pressed */
625 continue;
626 }
627 }
628 else if ((Char == '0') && (InputInEscTab))
629 {
630 /* It this ESC-TAB-0? */
633
634 /* If writes are already enabled, don't do this */
636 {
637 /* Reset the channel, this is our special sequence */
639 if (!NT_SUCCESS(Status)) break;
640 }
641
642 continue;
643 }
644 else
645 {
646 /* This is ESC-TAB-something else */
648
649 /* If writes are already enabled, don't do this */
651 {
652 /* Display the current channel */
655 if (!NT_SUCCESS(Status)) break;
656 continue;
657 }
658 }
659
660 /* Check if an ESC-sequence was being typed into a command channel */
662 {
663 /* Store the ESC in the current channel buffer */
664 ReadBuffer[0] = '\x1B';
666 }
667
668 /* Check if we are no longer pressing ESC and exit the mode if so */
669 if (Char != '\x1B') InputInEscape = FALSE;
670
671 /* Whatever was typed in, save it int eh current channel */
672 ChannelIWrite(CurrentChannel, &Char, sizeof(Char));
673
674 /* If this is a command channel, we're done, nothing to process */
675 if (CurrentChannel != SacChannel) continue;
676
677 /* Check for line feed right after a carriage return */
678 if ((ConMgrLastCharWasCR) && (Char == '\n'))
679 {
680 /* Ignore the line feed, but clear the carriage return */
683 continue;
684 }
685
686 /* Check if the user did a carriage return */
687 ConMgrLastCharWasCR = (Char == '\n');
688
689 /* If the user did an "ENTER", we need to run the command */
690 if ((Char == '\n') || (Char == '\r'))
691 {
692 /* Echo back to the terminal */
693 SacPutString(L"\r\n");
694
695DoLineParsing:
696 /* Inhibit the character (either CR or LF) */
698
699 /* NULL-terminate the channel's input buffer */
702
703 /* Loop over every last character */
704 do
705 {
706 /* Read every character in the channel, and strip whitespace */
708 ReadBuffer[0] = (CHAR) LastChar;
709 } while ((!(LastChar) ||
710 (LastChar == L' ') ||
711 (LastChar == L'\t')) &&
713
714 /* Write back into the channel the last character */
716
717 /* NULL-terminate the input buffer */
720
721 /* Now loop over every first character */
722 do
723 {
724 /* Read every character in the channel, and strip whitespace */
727 sizeof(ReadBuffer),
728 &ReadBufferSize);
729 } while ((ReadBufferSize) &&
730 ((ReadBuffer[0] == ' ') || (ReadBuffer[0] == '\t')));
731
732 /* We read one more than we should, so treat that as our first one */
733 InputBuffer[0] = ReadBuffer[0];
734 i = 1;
735
736 /* And now loop reading all the others */
737 do
738 {
739 /* Read each character -- there should be max 80 */
742 sizeof(ReadBuffer),
743 &ReadBufferSize);
745 InputBuffer[i++] = ReadBuffer[0];
746 } while (ReadBufferSize);
747
748 /* Now go over the entire input stream */
749 for (i = 0; InputBuffer[i]; i++)
750 {
751 /* Again it should be less than 80 characters */
753
754 /* And downbase each character */
755 Char = InputBuffer[i];
756 if ((Char >= 'A') && (Char <= 'Z')) InputBuffer[i] = Char + ' ';
757 }
758
759 /* Ok, at this point, no pending command should exist */
761
762 /* Go and process the input, then show the prompt again */
764 SacPutSimpleMessage(SAC_PROMPT);
765
766 /* If the user typed a valid command, get out of here */
768
769 /* Keep going */
770 continue;
771 }
772
773 /* Check if the user typed backspace or delete */
774 if ((Char == '\b') || (Char == '\x7F'))
775 {
776 /* Omit the last character, which should be the DEL/BS itself */
778 {
780 }
781
782 /* Omit the before-last character, which is the one to delete */
784 {
785 /* Also send two backspaces back to the console */
786 SacPutString(L"\b \b");
788 }
789
790 /* Keep going */
791 continue;
792 }
793
794 /* If the user pressed CTRL-C at this point, treat it like ENTER */
795 if (Char == '\x03') goto DoLineParsing;
796
797 /* Check if the user pressed TAB */
798 if (Char == '\t')
799 {
800 /* Omit it, send a BELL, and keep going. We ignore TABs */
802 SacPutString(L"\a");
803 continue;
804 }
805
806 /* Check if the user is getting close to the end of the screen */
808 {
809 /* Delete the last character, replacing it with this one instead */
810 swprintf(StringBuffer, L"\b%c", Char);
812
813 /* Omit the last two characters from the buffer */
816
817 /* Write the last character that was just typed in */
818 ReadBuffer[0] = Char;
820 continue;
821 }
822
823 /* Nothing of interest happened, just write the character back */
824 swprintf(StringBuffer, L"%c", Char);
826 }
827
828 /* We're done, release the lock */
830 SAC_DBG(SAC_DBG_MACHINE, "SAC TimerDpcRoutine: Exiting.\n"); //bug
831}
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
#define CHAR(Char)
ULONG NTAPI ChannelIBufferLength(IN PSAC_CHANNEL Channel)
Definition: channel.c:163
NTSTATUS NTAPI ChannelIRead(IN PSAC_CHANNEL Channel, IN PCHAR Buffer, IN ULONG BufferSize, IN OUT PULONG ResultBufferSize)
Definition: channel.c:131
NTSTATUS NTAPI ChannelIWrite(IN PSAC_CHANNEL Channel, IN PCHAR Buffer, IN ULONG BufferSize)
Definition: channel.c:116
WCHAR NTAPI ChannelIReadLast(IN PSAC_CHANNEL Channel)
Definition: channel.c:150
BOOLEAN InputInEscTab
Definition: conmgr.c:32
BOOLEAN InputInEscape
Definition: conmgr.c:32
NTSTATUS NTAPI ConMgrAdvanceCurrentChannel(VOID)
Definition: conmgr.c:410
VOID NTAPI ConMgrProcessInputLine(VOID)
Definition: conmgr.c:456
BOOLEAN ConMgrLastCharWasCR
Definition: conmgr.c:32
#define TRUE
Definition: types.h:120
#define swprintf
Definition: precomp.h:40
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
#define L(x)
Definition: ntvdm.h:50
#define SAC_DBG_MACHINE
Definition: sacdrv.h:36
NTSTATUS NTAPI SerialBufferGetChar(OUT PCHAR Char)
Definition: util.c:1212
#define SAC_VTUTF8_COL_WIDTH
Definition: sacdrv.h:157
@ Nothing
Definition: sacdrv.h:266
#define STATUS_NO_DATA_DETECTED
Definition: udferr_usr.h:131
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by ConMgrWorkerProcessEvents().

◆ ConMgrSetCurrentChannel()

NTSTATUS NTAPI ConMgrSetCurrentChannel ( IN PSAC_CHANNEL  Channel)

Definition at line 287 of file conmgr.c.

288{
290 BOOLEAN HasRedrawEvent;
291
292 /* Make sure the lock is held */
294
295 /* Check if we have a redraw event */
296 Status = ChannelHasRedrawEvent(CurrentChannel, &HasRedrawEvent);
297 if (!NT_SUCCESS(Status)) return Status;
298
299 /* Clear it */
300 if (HasRedrawEvent) ChannelClearRedrawEvent(CurrentChannel);
301
302 /* Disable writes on the current channel */
304
305 /* Release the current channel */
307 if (!NT_SUCCESS(Status)) return Status;
308
309 /* Set the new channel and also disable writes on it */
310 CurrentChannel = Channel;
311 _InterlockedExchange(&Channel->WriteEnabled, 0);
312 return STATUS_SUCCESS;
313}
NTSTATUS NTAPI ChanMgrReleaseChannel(IN PSAC_CHANNEL Channel)
Definition: chanmgr.c:243
NTSTATUS NTAPI ChannelClearRedrawEvent(IN PSAC_CHANNEL Channel)
Definition: channel.c:198

Referenced by ConMgrAdvanceCurrentChannel(), and ConMgrResetCurrentChannel().

◆ ConMgrShutdown()

NTSTATUS NTAPI ConMgrShutdown ( VOID  )

Definition at line 372 of file conmgr.c.

373{
375
376 /* Check if we have a SAC channel */
377 if (SacChannel)
378 {
379 /* Close it */
381 if (!NT_SUCCESS(Status))
382 {
383 SAC_DBG(SAC_DBG_INIT, "SAC ConMgrShutdown: failed closing SAC channel.\n");
384 }
385
386 /* No longer have one */
388 }
389
390 /* Check if we have a current channel */
391 if (CurrentChannel)
392 {
393 /* Release it */
395 if (!NT_SUCCESS(Status))
396 {
397 SAC_DBG(SAC_DBG_INIT, "SAC ConMgrShutdown: failed releasing current channel\n");
398 }
399
400 /* No longer have one */
402 }
403
404 /* All done */
405 return STATUS_SUCCESS;
406}
NTSTATUS NTAPI ChannelClose(IN PSAC_CHANNEL Channel)
Definition: channel.c:558

Referenced by FreeGlobalData().

◆ ConMgrSimpleEventMessage()

BOOLEAN NTAPI ConMgrSimpleEventMessage ( IN ULONG  MessageIndex,
IN BOOLEAN  LockHeld 
)

Definition at line 252 of file conmgr.c.

254{
255 PWCHAR MessageBuffer;
257
258 /* Get the message to send out */
259 MessageBuffer = GetMessage(MessageIndex);
260 if (MessageBuffer)
261 {
262 /* Send it */
263 ConMgrEventMessage(MessageBuffer, LockHeld);
264 Result = TRUE;
265 }
266 else
267 {
268 /* It doesn't exist, fail */
269 Result = FALSE;
270 }
271
272 /* Return if the message was sent or not */
273 return Result;
274}
VOID NTAPI ConMgrEventMessage(IN PWCHAR EventMessage, IN BOOLEAN LockHeld)
Definition: conmgr.c:235
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426

Referenced by DoRebootCommand().

◆ ConMgrWorkerProcessEvents()

VOID NTAPI ConMgrWorkerProcessEvents ( IN PSAC_DEVICE_EXTENSION  DeviceExtension)

Definition at line 835 of file conmgr.c.

836{
837 SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC WorkerProcessEvents: Entering.\n");
838
839 /* Enter the main loop */
840 while (TRUE)
841 {
842 /* Wait for something to do */
843 KeWaitForSingleObject(&DeviceExtension->Event,
844 Executive,
846 FALSE,
847 NULL);
848
849 /* Consume data off the serial port */
852 {
853 case Restart:
854 /* A reboot was sent, do it */
856 break;
857
858 case Close:
859 /* A close was sent, do it */
862 break;
863
864 case Shutdown:
865 /* A shutdown was sent, do it */
867 break;
868 }
869
870 /* Clear the serial port consumer state */
873 }
874}
NTSTATUS NTAPI ChanMgrCloseChannel(IN PSAC_CHANNEL Channel)
Definition: chanmgr.c:593
VOID NTAPI DoRebootCommand(IN BOOLEAN Reboot)
Definition: concmd.c:355
PSAC_CHANNEL ExecutePostConsumerCommandData
Definition: conmgr.c:30
VOID NTAPI ConMgrSerialPortConsumer(VOID)
Definition: conmgr.c:574
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KernelMode
Definition: asm.h:34
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
@ Close
Definition: sacdrv.h:268
@ Executive
Definition: ketypes.h:403

Referenced by WorkerProcessEvents().

◆ ConMgrWriteData()

NTSTATUS NTAPI ConMgrWriteData ( IN PSAC_CHANNEL  Channel,
IN PVOID  Buffer,
IN ULONG  BufferLength 
)

Definition at line 111 of file conmgr.c.

114{
115 ULONG i;
118
119 /* Loop up to 32 times */
120 for (i = 0; i < 32; i++)
121 {
122 /* Attempt sending the data */
124 if (Status != STATUS_UNSUCCESSFUL) break;
125
126 /* Sending the data on the port failed, wait a second... */
127 Interval.HighPart = -1;
128 Interval.LowPart = -100000;
130 }
131
132 /* After 32 attempts it should really have worked... */
134 return Status;
135}
Definition: bufpool.h:45
#define KeDelayExecutionThread(mode, foo, t)
Definition: env_spec_w32.h:484
@ HeadlessCmdPutData
Definition: hdl.h:150
DWORD Interval
Definition: netstat.c:33
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

Referenced by RawChannelOEcho(), RawChannelOFlush(), VTUTF8ChannelAnsiDispatch(), VTUTF8ChannelOEcho(), and VTUTF8ChannelOFlush().

◆ DEFINE_GUID()

DEFINE_GUID ( PRIMARY_SAC_CHANNEL_APPLICATION_GUID  ,
0x63D02270  ,
0x8AA4  ,
0x11D5  ,
0xBC  ,
0xCF  ,
0x80  ,
0x6D  ,
0x61  ,
0x72  ,
0x69  ,
0x6F   
)

◆ SacPutSimpleMessage()

BOOLEAN NTAPI SacPutSimpleMessage ( IN ULONG  MessageIndex)

Definition at line 57 of file conmgr.c.

58{
59 PWCHAR MessageBuffer;
61
62 /* Get the message */
63 MessageBuffer = GetMessage(MessageIndex);
64 if (MessageBuffer)
65 {
66 /* Output it */
67 SacPutString(MessageBuffer);
68 Result = TRUE;
69 }
70 else
71 {
72 Result = FALSE;
73 }
74
75 /* All done */
76 return Result;
77}

Referenced by ConMgrEventMessage(), ConMgrInitialize(), ConMgrProcessInputLine(), ConMgrSerialPortConsumer(), DoFullInfoCommand(), DoPagingCommand(), DoRebootCommand(), DoTlistCommand(), and PrintHelpMessage().

◆ SacPutString()

VOID NTAPI SacPutString ( IN PWCHAR  String)

Definition at line 41 of file conmgr.c.

42{
44
45 /* Write the string on the main SAC channel */
48 wcslen(String) * sizeof(WCHAR));
49 if (!NT_SUCCESS(Status))
50 {
51 SAC_DBG(SAC_DBG_INIT, "SAC XmlMgrSacPutString: OWrite failed\n");
52 }
53}
NTSTATUS NTAPI ChannelOWrite(IN PSAC_CHANNEL Channel, IN PCHAR Buffer, IN ULONG BufferSize)
Definition: channel.c:87
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by ConMgrEventMessage(), ConMgrSerialPortConsumer(), DoRebootCommand(), DoTlistCommand(), and SacPutSimpleMessage().

Variable Documentation

◆ ConMgrLastCharWasCR

BOOLEAN ConMgrLastCharWasCR

Definition at line 32 of file conmgr.c.

Referenced by ConMgrSerialPortConsumer().

◆ CurrentChannel

◆ CurrentChannelLock

KMUTEX CurrentChannelLock

◆ CurrentChannelRefCount

LONG CurrentChannelRefCount

◆ ExecutePostConsumerCommand

ULONG ExecutePostConsumerCommand

◆ ExecutePostConsumerCommandData

PSAC_CHANNEL ExecutePostConsumerCommandData

Definition at line 30 of file conmgr.c.

Referenced by ConMgrWorkerProcessEvents().

◆ GlobalDoThreads

BOOLEAN GlobalDoThreads

Definition at line 35 of file conmgr.c.

Referenced by DoFullInfoCommand().

◆ GlobalPagingNeeded

BOOLEAN GlobalPagingNeeded

Definition at line 35 of file conmgr.c.

Referenced by ConMgrProcessInputLine(), and DoPagingCommand().

◆ InputBuffer

Definition at line 33 of file conmgr.c.

◆ InputInEscape

BOOLEAN InputInEscape

Definition at line 32 of file conmgr.c.

Referenced by ConMgrSerialPortConsumer().

◆ InputInEscTab

BOOLEAN InputInEscTab

Definition at line 32 of file conmgr.c.

Referenced by ConMgrSerialPortConsumer().

◆ SacChannel