示例#1
0
        //static Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        public static void FirmwareLoadUtil(Reader reader, Stream firmware, FixedReaderFirmwareLoadOptions rflOptions, string hostName, ref Socket socket)
        {
            // Assume that a system with an RQL interpreter has the standard
            // web interface and password. This isn't really an RQL operation,
            // but it will work most of the time
            HttpWebRequest req = null;// = MakeWebReq("/cgi-bin/firmware.cgi");
            string         uri = (string)reader.ParamGet("/reader/uri");

            // Filename "firmware.tmfw" is arbitrary -- server always ignores
            // Fixed reader firmware is huge (~7MB).
            // Increase the default timeout to allow sufficient upload time
            // (Default timeout is 100 seconds)
            if (null == rflOptions)
            {
                req = MakeWebReq("/cgi-bin/firmware.cgi", hostName);
            }
            else
            {
                FixedReaderFirmwareLoadOptions objrflOptions;
                objrflOptions = (FixedReaderFirmwareLoadOptions)rflOptions;
                if ((!objrflOptions.EraseContents) && (!objrflOptions.RevertDefaultSettings))
                {
                    req = MakeWebReq("/cgi-bin/firmware.cgi", hostName);
                }
                else if ((!objrflOptions.EraseContents) && (objrflOptions.RevertDefaultSettings))
                {
                    throw new ReaderException("Un supported option type");
                }
                else if (objrflOptions.EraseContents && objrflOptions.RevertDefaultSettings)
                {
                    req = MakeWebReq("/cgi-bin/firmware.cgi?revert=true&wipe=true&DOWNGRADE=Continue", hostName);
                }
                else if ((objrflOptions.EraseContents) && (!objrflOptions.RevertDefaultSettings))
                {
                    req = MakeWebReq("/cgi-bin/firmware.cgi?wipe=true&DOWNGRADE=Continue", hostName);
                }
            }
            req.Timeout = 10 * 60 * 1000;
            WebUploadFile(req, firmware, "firmware.tmfw");

            HttpWebResponse rsp      = (HttpWebResponse)req.GetResponse();
            string          response = WebRespToString(rsp);

            if ((0 <= response.IndexOf("Firmware file uploaded")) || (0 <= response.IndexOf("Press Continue to install")))
            {
                //WebRespToString((HttpWebResponse)MakeWebReq("/cgi-bin/firmware.cgi?confirm=true", hostName
                //    ).GetResponse());
                req         = MakeWebReq("/cgi-bin/firmware.cgi?confirm=true", hostName);
                req.Timeout = 150 * 1000;
                WebRespToString((HttpWebResponse)req.GetResponse());
            }
            else if ((0 <= response.IndexOf("replace the new firmware with older firmware")))
            {
                // If asked to confirm using an older firmware, respond
                //WebRespToString((HttpWebResponse)MakeWebReq("/cgi-bin/firmware.cgi?wipe=true&confirm=true&DOWNGRADE=Continue", hostName
                //    ).GetResponse());
                req         = MakeWebReq("/cgi-bin/firmware.cgi?wipe=true&confirm=true&DOWNGRADE=Continue", hostName);
                req.Timeout = 150 * 1000;
                WebRespToString((HttpWebResponse)req.GetResponse());
            }

            // If firmware load succeeded, reboot to make it take effect
            if ((0 <= response.IndexOf("Firmware update complete")) || (0 <= response.IndexOf("Firmware upgrade started")))
            {
                // Restart reader
                HttpWebRequest rebootReq = MakeWebReq("/cgi-bin/reset.cgi", hostName);
                WebPost(rebootReq, "dummy=dummy");
                // TODO: Use a more sophisticated method to detect when the reader is ready again
                System.Threading.Thread.Sleep(90 * 1000);
            }
            else
            {
                throw new ReaderException("Firmware update failed");
            }
        }
示例#2
0
        //static Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        public static void FirmwareLoadUtil(Reader reader, Stream firmware, FixedReaderFirmwareLoadOptions rflOptions, string hostName, ref Socket socket)
        {
            // Assume that a system with an RQL interpreter has the standard
            // web interface and password. This isn't really an RQL operation,
            // but it will work most of the time
            HttpWebRequest req = null;// = MakeWebReq("/cgi-bin/firmware.cgi");
            string uri = (string)reader.ParamGet("/reader/uri");

            // Filename "firmware.tmfw" is arbitrary -- server always ignores
            // Fixed reader firmware is huge (~7MB).
            // Increase the default timeout to allow sufficient upload time
            // (Default timeout is 100 seconds)
            if (null == rflOptions)
            {
                req = MakeWebReq("/cgi-bin/firmware.cgi",hostName);
            }
            else
            {
                FixedReaderFirmwareLoadOptions objrflOptions;
                objrflOptions = (FixedReaderFirmwareLoadOptions)rflOptions;
                if ((!objrflOptions.EraseContents) && (!objrflOptions.RevertDefaultSettings))
                {
                    req = MakeWebReq("/cgi-bin/firmware.cgi", hostName);
                }
                else if ((!objrflOptions.EraseContents) && (objrflOptions.RevertDefaultSettings))
                {
                    throw new ReaderException("Un supported option type");
                }
                else if (objrflOptions.EraseContents && objrflOptions.RevertDefaultSettings)
                {
                    req = MakeWebReq("/cgi-bin/firmware.cgi?revert=true&wipe=true&DOWNGRADE=Continue", hostName);
                }
                else if ((objrflOptions.EraseContents) && (!objrflOptions.RevertDefaultSettings))
                {
                    req = MakeWebReq("/cgi-bin/firmware.cgi?wipe=true&DOWNGRADE=Continue", hostName);
                }
            }
            req.Timeout = 10 * 60 * 1000;
            WebUploadFile(req, firmware, "firmware.tmfw");

            HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
            string response = WebRespToString(rsp);

            if ((0 <= response.IndexOf("Firmware file uploaded")) || (0 <= response.IndexOf("Press Continue to install")))
            {
                WebRespToString((HttpWebResponse)MakeWebReq("/cgi-bin/firmware.cgi?confirm=true", hostName
                    ).GetResponse());
            }
            else if ((0 <= response.IndexOf("replace the new firmware with older firmware")))
            {
                // If asked to confirm using an older firmware, respond
                WebRespToString((HttpWebResponse)MakeWebReq("/cgi-bin/firmware.cgi?wipe=true&confirm=true&DOWNGRADE=Continue", hostName
                    ).GetResponse());
            }

            // If firmware load succeeded, reboot to make it take effect
            if ((0 <= response.IndexOf("Firmware update complete")) || (0 <= response.IndexOf("Firmware upgrade started")))
            {
                // Restart reader
                HttpWebRequest rebootReq = MakeWebReq("/cgi-bin/reset.cgi",hostName);
                WebPost(rebootReq, "dummy=dummy");
                // TODO: Use a more sophisticated method to detect when the reader is ready again
                System.Threading.Thread.Sleep(90 * 1000);
            
           }
            else
                throw new ReaderException("Firmware update failed");
        }