예제 #1
1
 private static Line GetCellLine(Tapi tapi)
 {
     for (int count = 0; count <tapi.NumDevices; count++)
      {
          try
          {
              LINEDEVCAPS dc = new LINEDEVCAPS(1024);
              dc.Store();
              int dwVersion = tapi.NegotiateVersion(count);
              NativeTapi.lineGetDevCaps(tapi.hLineApp, count, dwVersion, 0, dc.Data);
              dc.Load();
              if (dc.LineName == CellTSP.CELLTSP_LINENAME_STRING)
              {
                  return tapi.CreateLine(count, LINEMEDIAMODE.INTERACTIVEVOICE, LINECALLPRIVILEGE.OWNER);
              }
          }
          catch { }
      }
      return null;
 }
예제 #2
0
 public static void EnableFlightMode()
 {
     Tapi tapi = new Tapi();
      tapi.Initialize();
      Line thisLine = GetCellLine(tapi);
      if (thisLine == null) return;
      CellTSP.lineSetEquipmentState(thisLine.hLine, (int)LINEEQUIPSTATE.MINIMUM);
      thisLine.Dispose();
      tapi.Shutdown();
 }
예제 #3
0
 public static void DisableFlightMode()
 {
     Tapi tapi = new Tapi();
      tapi.Initialize();
      Line thisLine = GetCellLine(tapi);
      if (thisLine == null) return;
      CellTSP.lineSetEquipmentState(thisLine.hLine, (int)LINEEQUIPSTATE.FULL);
      CellTSP.lineRegister(thisLine.hLine, (int)LINEREGMODE.AUTOMATIC, "", 0);
      thisLine.Dispose();
      tapi.Shutdown();
 }
예제 #4
0
        //# __________ PROTOCOL :: INTERNET CONNECTION TESTING __________ #//
        public static bool IsDeviceInFlightMode()
        {
            int result = 0;
             LINERADIOSUPPORT cellstate = LINERADIOSUPPORT.UNKNOWN;

             Tapi tapi = new Tapi();
             tapi.Initialize();
             Line thisLine = GetCellLine(tapi);
             if (thisLine == null) return false;
             if (CellTSP.lineGetEquipmentState(thisLine.hLine, out result, out cellstate) != 0) MessageBox.Show("Tapi failed.");
             thisLine.Dispose();
             tapi.Shutdown();
             return result == (int)LINEEQUIPSTATE.MINIMUM;
        }
예제 #5
0
        /* start - process arguments */
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            tapi     = new Tapi();
            network  = new Network();
            registry = new RegEdit();
            setup    = new Settings(); // sets defaults, load setup from registry, override setup with values given by the starting args
            registry.readAll();        // try to override the defaults with the values stored in the registry
            string arg, value;
            bool   isShowPossibleArgs = false;

            if (e.Args.Length > 0)
            {
                App.log("Overriding settings using startup arguments");
                for (int i = 0; i != e.Args.Length; ++i)
                {
                    value = "";
                    arg   = e.Args[i]; // -S127.0.0.1
                    if (arg.StartsWith("-"))
                    {
                        if (arg.Length > 2)
                        {
                            value = arg.Substring(2);
                            if (value != "")
                            {
                                switch (arg.Substring(0, 2))
                                {
                                case "-S":
                                    App.Setup.Server = value;
                                    break;

                                case "-P":
                                    App.Setup.Port = value;
                                    break;

                                case "-E":
                                    App.Setup.Extension = value;
                                    break;

                                case "-D":
                                    App.Setup.Line = value;
                                    break;

                                case "-A":
                                    App.Setup.Address = value;
                                    break;

                                default:
                                    App.log("Unknown arg received: " + arg);
                                    isShowPossibleArgs = true;
                                    break;
                                }
                            }
                        }
                        if (arg.Length > 6)
                        {
                            if (arg.Substring(0, 6) == "-debug")
                            {
                                App.Setup.Debugfilename = arg.Substring(6);
                            }
                        }
                    }
                    else
                    {
                        App.log("Invalid arg format: " + arg);
                    }
                }
            }
            else
            {
                startAppSilent = false; // if no args are given, show a BalloonTip briefly.
            }
            if (isShowPossibleArgs)
            {
                App.log("Valid args are : -S.., -P.., -E.., -D.., -A.., -debug..");
            }
        }
예제 #6
0
        //original code location:
        //http://www.developersdex.com/vb/message.asp?p=2916&ID=%3C68D1F07B-ECB0-4A15-AFCA-2A911FC3234C%40microsoft.com%3E
        /// <summary>
        /// Gets general information about the device.
        /// </summary>
        /// <param name="manufacturer">Manufacturer.</param>
        /// <param name="model">Model.</param>
        /// <param name="revision">Revision.</param>
        /// <param name="serialNumber">IMEI.</param>
        /// <param name="subsciberId">IMSI.</param>
        public static void Get(out string manufacturer, out string model, out string revision, out string serialNumber, out string subsciberId)
        {
            IntPtr hLine;
            int    dwNumDev;
            int    num1 = 0x20000;
            LINEINITIALIZEEXPARAMS lineInitializeParams = new LINEINITIALIZEEXPARAMS();

            lineInitializeParams.dwTotalSize     = (uint)Marshal.SizeOf(lineInitializeParams);
            lineInitializeParams.dwNeededSize    = lineInitializeParams.dwTotalSize;
            lineInitializeParams.dwOptions       = 2;
            lineInitializeParams.hEvent          = IntPtr.Zero;
            lineInitializeParams.hCompletionPort = IntPtr.Zero;
            #region lineInitializeEx

            int result = Tapi.lineInitializeEx(out hLine, IntPtr.Zero,
                                               IntPtr.Zero, null, out dwNumDev, ref num1, ref lineInitializeParams);
            if (result != 0)
            {
                throw new ApplicationException(string.Format("lineInitializeEx failed!\n\nError Code:{0}", result.ToString()));
            }

            #endregion

            #region lineNegotiateAPIVerison

            int             version;
            int             dwAPIVersionLow  = 0x10004;
            int             dwAPIVersionHigh = 0x20000;
            LINEEXTENSIONID lineExtensionID;
            result = Tapi.lineNegotiateAPIVersion(hLine, 0, dwAPIVersionLow, dwAPIVersionHigh, out version, out lineExtensionID);
            if (result != 0)
            {
                throw new ApplicationException(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString()));
            }

            #endregion

            #region lineOpen

            IntPtr hLine2 = IntPtr.Zero;
            result = Tapi.lineOpen(hLine, 0, out hLine2, version, 0, IntPtr.Zero, 0x00000002, 0x00000004, IntPtr.Zero);
            if (result != 0)
            {
                throw new ApplicationException(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString()));
            }

            #endregion

            #region lineGetGeneralInfo

            int    structSize = Marshal.SizeOf(new LINEGENERALINFO());
            byte[] bytes      = new byte[structSize];
            byte[] tmpBytes   = BitConverter.GetBytes(structSize);

            for (int index = 0; index < tmpBytes.Length; index++)
            {
                bytes[index] = tmpBytes[index];
            }

            #endregion

            #region make initial query to retrieve necessary size
            result = Tapi.lineGetGeneralInfo(hLine2, bytes);

            // get the needed size
            int neededSize = BitConverter.ToInt32(bytes, 4);

            // resize the array
            bytes = new byte[neededSize];

            // write out the new allocated size to the byte stream
            tmpBytes = BitConverter.GetBytes(neededSize);
            for (int index = 0; index < tmpBytes.Length; index++)
            {
                bytes[index] = tmpBytes[index];
            }

            // fetch the information with properly size buffer
            result = Tapi.lineGetGeneralInfo(hLine2, bytes);

            if (result != 0)
            {
#if DEBUG
                throw new ApplicationException(Marshal.GetLastWin32Error().ToString());
#endif

                //tear down
                Tapi.lineClose(hLine2);
                Tapi.lineShutdown(hLine);

                manufacturer = String.Empty;
                model        = String.Empty;
                revision     = String.Empty;

                serialNumber = String.Empty;
                subsciberId  = String.Empty;
                return;
            }

            #endregion

            #region actual data fetching

            int size;
            int offset;

            // manufacture
            size         = BitConverter.ToInt32(bytes, 12);
            offset       = BitConverter.ToInt32(bytes, 16);
            manufacturer = Encoding.Unicode.GetString(bytes, offset, size);
            manufacturer = manufacturer.Substring(0, manufacturer.IndexOf('\0'));

            // model
            size   = BitConverter.ToInt32(bytes, 20);
            offset = BitConverter.ToInt32(bytes, 24);
            model  = Encoding.Unicode.GetString(bytes, offset, size);
            model  = model.Substring(0, model.IndexOf('\0'));

            // revision
            size     = BitConverter.ToInt32(bytes, 28);
            offset   = BitConverter.ToInt32(bytes, 32);
            revision = Encoding.Unicode.GetString(bytes, offset, size);
            revision = revision.Substring(0, revision.IndexOf('\0'));

            // serial number
            size         = BitConverter.ToInt32(bytes, 36);
            offset       = BitConverter.ToInt32(bytes, 40);
            serialNumber = Encoding.Unicode.GetString(bytes, offset, size);
            serialNumber = serialNumber.Substring(0, serialNumber.IndexOf('\0'));

            // subscriber id
            size        = BitConverter.ToInt32(bytes, 44);
            offset      = BitConverter.ToInt32(bytes, 48);
            subsciberId = Encoding.Unicode.GetString(bytes, offset, size);
            subsciberId = subsciberId.Substring(0, subsciberId.IndexOf('\0'));

            #endregion


            //tear down
            Tapi.lineClose(hLine2);
            Tapi.lineShutdown(hLine);
        }