Open Com2 to send AT command faild - Windows Mobile Development and Hacking General

Hi,
I want to use AT commands over RIL on my HTC tornado (T-Mobile SDA). But if I open com2, it failed (return false).
Code:
hCom=CreateFile(L"COM2:" ,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (hCom==NULL || hCom==INVALID_HANDLE_VALUE)
{
hCom= NULL;
TRACE(TEXT("E1\n"));
return false;
}
Have I to aktivate COM2, before?
How to do it?
Thanks
Thomas

http://www.teksoftco.com/forum/viewtopic.php?t=43

Related

Modem comunication on WM2005 (AT command)

We have developped an application on WM2002 and WM2003 that use PDA modem to communicate with a remote device.
We worked with QTEK 2020 and QTEK 9090.
Last month we must porting the application on WM2005 (JAMin PDA), but we founded problems with the AT commands sent on the modem.
The code that open the modem is:
// initialize RIL COM
if (!RIL_Initialize(1, NULL, NULL, 0x00040000L, NULL, &m_hRil))
{
error("RIL_Initialize");
ResTMP= 1;
}
// open COM2 (to send AT command to the modem)
m_hCom=CreateFile(CommandPort,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if (m_hCom==NULL || m_hCom==INVALID_HANDLE_VALUE)
{
error("CreateFile()");
m_hCom= NULL;
return 2;
}
// set COM setting
DCB dcb;
if (!GetCommState(m_hCom, &dcb))
{
error("GetCommState");
ResTMP= 3;
}
dcb.BaudRate= CBR_115200;
dcb.ByteSize= 8;
dcb.fParity= false;
dcb.StopBits= ONESTOPBIT;
if (!SetCommState(m_hCom, &dcb))
{
error("SetCommState");
ResTMP= 4;
}
if (!EscapeCommFunction(m_hCom, SETDTR))
{
error("SETDTR");
ResTMP= 5;
}
COMMTIMEOUTS to;
if (!GetCommTimeouts(m_hCom, &to))
{
error("GetCommTimeouts");
ResTMP= 7;
}
to.ReadIntervalTimeout= 0;
to.ReadTotalTimeoutConstant= 200;
to.ReadTotalTimeoutMultiplier= 0;
to.WriteTotalTimeoutConstant= 20000;
to.WriteTotalTimeoutMultiplier= 0;
if (!SetCommTimeouts(m_hCom, &to))
{
error("SetCommTimeouts");
ResTMP= 8;
}
if (!SetCommMask(m_hCom, EV_RXCHAR))
{
error("SetCommMask");
ResTMP= 9;
}
// open RIL2 (radio)
m_hRil= CreateFile(RadioPort,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_SYSTEM,0);
if (m_hRil==NULL || m_hRil==INVALID_HANDLE_VALUE)
{
error("CreateFile()");
return 10;
}
// send command to radio handle to turn off the phone and release the modem
DWORD rildevresult;
if (!DeviceIoControl(m_hRil, 0x03000314L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0))
{
error("DeviceIoControl ril 0x03000314L");
ResTMP= 11;
}
// send command to modem to enable it
BYTE comdevcmd[2]= {0x84, 0x00};
if (!DeviceIoControl(m_hCom,0xAAAA5679L, comdevcmd, sizeof(comdevcmd),0,0,0,0))
{
error("DeviceIoControl com 0xAAAA5679L");
ResTMP= 12;
}
The red code not works on WM2005, therefore the radio is not released and the AT commands sent on COM2 not produce.
Sorry...
the red code is:
if (!DeviceIoControl(m_hRil, 0x03000314L,0,0, &rildevresult, sizeof(DWORD), &nReturned,0))
{
error("DeviceIoControl ril 0x03000314L");
ResTMP= 11;
}
It's great!
mmarco_hes said:
We worked with QTEK 2020 and QTEK 9090.
Last month we must porting the application on WM2005 (JAMin PDA), but we founded problems with the AT commands sent on the modem.
The red code not works on WM2005, therefore the radio is not released and the AT commands sent on COM2 not produce.
Click to expand...
Click to collapse
Some people seem to have solved this. The Universal unlocker on buzzdev.net contains the correct calls. You might want to take a peek at that binary... (IDA required).
bigmac
Hi bigmac, I have not found nothing on buzzdev.net that can help me to solve this problem.
You have any idea how I can found the information in the site buzzdev.net that can help me?
Tank's!
Hi mmarco_hes!
I have the same problem with the "red code" on my WM5 device.
Do you found the reason or a solution for this problem ?
Thank´s in advance.
Regards Jogi
I see COM7 on MDAPro Universal ist GSM/GPRS port. I can open it via createfile, but i can't send DeviceIoControl code:
BYTE comdevcmd[2]= {0x84, 0x00};
if (!DeviceIoControl (m_hCom,0xAAAA5679L, comdevcmd, sizeof(comdevcmd),0,0,0,0))
{
error("DeviceIoControl com 0xAAAA5679L");
return false;
}
What is the real code on MDAPro ?

Problem creating a windows socket for bluetooth

When I try to create a socket in a C++ program I get an INVALID_SOCKET.
I've used the code shown below and the error code from the socket function
is 10047, which according to MSDN is WSAEAFNOSUPPORT (Address family not supported by protocol family)
I've used the exact same piece of code on a HTC Touch Diamond 2 and it works. The problem only appears on the HD2.
Any help would be appreciated.
Thanks,
TJ
// Initialize WSA
WORD wVersionRequested = MAKEWORD(2,2);
if (WSAStartup(wVersionRequested, &m_wsaData) != 0)
{
Log(L"Failed to start WSA");
return false;
}
if ( LOBYTE( m_wsaData.wVersion ) != 2 ||
HIBYTE( m_wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
Log(L"Wrong winsock version");
WSACleanup( );
return false;
}
// Create the listening socket
m_listenSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
if (INVALID_SOCKET == m_listenSocket)
{
std::stringstream errorMessage;
errorMessage << "ERROR: Could not create socket.\n Error code: " << GetLastError();
Log(A2W(errorMessage.str().c_str()));
return false;
}

AT Command to gsm module in WM6

Hello everyone,
This topic is not new however i never see any thread that has the solution for WM6. In my case, i want to create an smartphone app send AT Command to the gsm modem of my HTC HD.
Apparently there's no port COM2 or COM9 open in the device (everytime i tried CreateFile there's error 55, i also checked in the active device registry, no COM2 or COM9), so i use RIL_Initialize and RIL_GetSerialPortHandle to get the port. The openning and writing steps works very well, however there's no data in return, seems that the modem doesn't respond.
Below is the code:
Code:
RIL_Initialize(1,
ResultCallback,
NotifyCallback,
dwNotifications,
dwParam,
&RilHandle);
HANDLE hCom = NULL;
char * xpos;
char rsltstr[5];
DWORD returnValue;
DWORD LAC;
DWORD CellId;
int bufpos;
DCB dcb;
COMMTIMEOUTS to;
DWORD nWritten;
DWORD event1;
DWORD nRead;
char outbuf[20], buf[256];
BYTE comdevcmd[2]= {0x84, 0x00};
GetSerialPortHandleResult = RIL_GetSerialPortHandle(RilHandle,&hCom);
if (FAILED(GetSerialPortHandleResult))
{
TCHAR szString[256];
wsprintf(szString, L"Error GetSerialPortHandle, result= %d",GetSerialPortHandleResult);
MessageBox(NULL, szString, L"Error", MB_OK | MB_ICONERROR);
return 0;
}
if (hCom==NULL || hCom==INVALID_HANDLE_VALUE)
{
TCHAR szBuf[80];
DWORD dw = GetLastError();
// get the most uptodate cells
_stprintf(szBuf, TEXT("CreateFile failed with error %d."), dw);
MessageBox(0, szBuf, TEXT("Error"), MB_OK);
hCom= NULL;
return -1;
}
if (!GetCommState(hCom, &dcb))
{
return -2;
}
dcb.BaudRate= CBR_115200;
dcb.ByteSize= 8;
dcb.fParity= false;
dcb.StopBits= ONESTOPBIT;
if (!SetCommState(hCom, &dcb))
{
return -3;
}
if (!EscapeCommFunction(hCom, SETDTR))
{
return -4;
}
if (!GetCommTimeouts(hCom, &to))
{
return -6;
}
to.ReadIntervalTimeout= 0;
to.ReadTotalTimeoutConstant= 200;
to.ReadTotalTimeoutMultiplier= 0;
to.WriteTotalTimeoutConstant= 20000;
to.WriteTotalTimeoutMultiplier= 0;
if (!SetCommTimeouts(hCom, &to))
{
return -7;
}
if (!SetCommMask(hCom, EV_RXCHAR))
{
return -8;
}
if (!DeviceIoControl (hCom,0xAAAA5679L, comdevcmd,sizeof(comdevcmd),0,0,0,0))
{
TCHAR szBuf[80];
DWORD dw = GetLastError();
// get the most uptodate cells
_stprintf(szBuf, TEXT("DeviceIoControl failed with error %d."), dw);
MessageBox(NULL,szBuf, TEXT("Error"), MB_OK);
return -9;
}
bufpos = 0;
strcpy(outbuf,"AT+creg=2\r");
if (!WriteFile(hCom, outbuf, strlen(outbuf), &nWritten, NULL))
{
return -10;
}
if (nWritten != strlen(outbuf))
{
return -11;
}
/*if (!WaitCommEvent(hCom, &event1, NULL)) // ALWAYS BLOCKED !!!
{
return -12;
}*/Sleep(500);
while(1)
{
if (!ReadFile(hCom, buf+bufpos, 256 - bufpos, &nRead, NULL))
{
return -13;
}
if (nRead == 0) // ALWAYS BREAKS !!!
break;
bufpos += nRead;
if (bufpos >= 256)
break;
}
strcpy(outbuf,"AT+creg?\r");
... // Continue to write and read
As i said above, there's no return error, just that the buffer read is empty...
Any ideas ?
Thanks!
I don't know why it always gets nRead = 0, all the other steps work very well, no error return ...
I saw several discussions about this, so i do believe that someone have tried once this dev in WM5 or 6...
Therefore could anyone please share some point ?
no one has an idea ?
There's something a little bit interesting that i found out directly in the memory.
There's a sequence of responses to AT Command writing in ASCII:
@HTCCSQ:3
@HTCCSQ:4
@HTCCSQ:2
+CREG: 1,"000C","9F60" (here we has current LAC + Cell ID)
+CREG: 1,"000C","9BC7" (another LAC + Cell ID, i think it's the previous one)
+COPS: 0,2,"20820",3 (inside the "" are MCC MNC)
@HTCCSQ:3 .... (there's plenty of @HTCCSQ: coming next )
Look like some kind of log of the querries of RIL driver to the modem (i'm not sure)
So i think the gsm modem is available for answering to the commands, just haven't figured out how to make a stream connection to it (in WM6).
Any ideas ?
Thanks.
TAPI
I heard somewhere that we can use TAPI to send some AT Command, my question is to know if we can send a custom command (for example AT+CCED) by using TAPI ?
hi,I met the same problem.Do you find the answer?
Thanks.

[Q] Problem to run the Torch from source

Hello, i have downloaded the Torch source code from cyanogen repository and i have this problem:
1º I put the code in a empty project in Eclipse
2º I havent errors and the code compile correctly
3º I run the app in my device (Nexus One) and work well all buttons and options, but when i press in "On" button for active i get a error and the app crash.
Debugging i have seen the following:
For active flash i have put a "1" in file "/sys/devices/platform/flashlight.0/leds/flashlight/brightness" (If i put a "1" manually with terminal the flash is active correctly)
In code, we have this:
public class FlashDevice {
private static final String DEVICE = "/sys/devices/platform/flashlight.0/leds/flashlight/brightness";
...
public synchronized void setFlashMode(int mode) {
try {
if (mWriter == null) {
mWriter = new FileWriter(DEVICE);
}
int value = mode;
switch (mode) {
case STROBE:
value = OFF;
break;
case DEATH_RAY:
value = useDeathRay ? DEATH_RAY : HIGH;
break;
}
mWriter.write(String.valueOf(value));
mWriter.flush();
mFlashMode = mode;
if (mode == OFF) {
mWriter.close();
mWriter = null;
}
} catch (IOException e) {
throw new RuntimeException("Can't open flash device: " + DEVICE, e);
}
}
public synchronized int getFlashMode() {
return mFlashMode;
}
}
Click to expand...
Click to collapse
I get this error in line "mWriter = new FileWriter(DEVICE);":
java.io.FileNotFoundException: /sys/devices/platform/flashlight.0/leds/flashlight/brightness (Permission denied)
Someone know the cause????
Try using the original source code from the repository by
Code:
svn checkout http://n1torch.googlecode.com/svn/trunk/ n1torch-read-only
and importing it as a project into eclipse.

[Q] Exchanging Data between an Android App and JSP Website

Hi, guys! I have a basic understanding of Android App Development but the this thing is driving me nuts. I tired of searching all through the net and presume that XDA superheads can give me a perfect solution for this. At Least at any tutorial to clean my way would be appreciable!
Basically, my Android APP will have a EditText for UserName and Password that need to be send to a JSP based Website(xxxxxxxx/YouLogin.jsp).
Here is a Screenshot of the JSP Area and similar will be found in my APP even.!
See attachment 1:
The Source code of the YouLogin.jsp is
Code:
<script>
function LoadLoginPage(){
urlNew="youLoginResources.jsp?resource=0&loginerror= ";
GetAjaxTemplates(urlNew,'form01');
}
function LoadRegistration(){
urlNew="UserRegistration.jsp";
GetAjaxTemplates(urlNew,'form01');
}
function LoadRegistrationParent(){
urlNew="StudentParentLogin.jsp";
GetAjaxTemplates(urlNew,'form01');
}
function LoadRegistrationError(){
urlNew="UserRegistration.jsp?error=1";
GetAjaxTemplates(urlNew,'form01');
}
function LoadForgetPassword(){
urlNew="youLoginResources.jsp?resource=1&result=0";
GetAjaxTemplates(urlNew,'form01');
}
function LoadForgetPasswordResult(arg,mail){
urlNew="youLoginResources.jsp?resource=1&result="+arg+"&email="+mail;
GetAjaxTemplates(urlNew,'form01');
}
function submitData(){
document.getElementById('txtSN').value=document.getElementById('txtRegNumber').value;
document.getElementById('txtPD').value=document.getElementById('txtPwd').value;
if(document.getElementById('txtSN').value == '' || document.getElementById('txtSN').length == 0) {
alert(' Please Enter Student Register No/Studen ID');
document.getElementById('txtSN').focus();
return false;
}
if(document.getElementById('txtPD').value == '' || document.getElementById('txtPD').length == 0) {
alert(' Please Enter Password');
document.getElementById('txtPD').focus();
return false;
}
document.getElementById('txtPA').value=1;
document.getElementById('txtRegNumber').value="iamalsouser";
document.getElementById('txtPwd').value="thanksandregards";
document.getElementById('frmStudentMain').action="youLogin.jsp";
document.getElementById('frmStudentMain').submit();
}
function submitRegistrationData(){
if (CheckValidateRegData()){
document.getElementById('txtPA').value=2;
document.getElementById('frmStudentMain').action="youLogin.jsp";
document.getElementById('frmStudentMain').submit();
}
}
function disableEmail(arg){
arg=arg.toUpperCase();
if ((arg.length>3) && (arg.charAt(0)=='P')){
document.getElementById('txtMailid').disabled=true;
}else{
document.getElementById('txtMailid').disabled=false;
}
}
function submitForgetPwdData(){
if (ValidateForgetPwdData()){
document.getElementById('txtPA').value=3;
document.getElementById('frmStudentMain').action="youLogin.jsp";
document.getElementById('frmStudentMain').submit();
}
}
function CheckValidateRegData(){
// CheckBLank("txtemailid","Email")&&CheckEmail("txtemailid","Email") && -- for removing validation of email
if(
CheckBLank("txtoldpassword","Old Password") && CheckAlphaNum("txtoldpassword","Old Password") &&
CheckBLank("txtnewpassword1"," New Password") && CheckAlphaNum("txtnewpassword1","New Password") &&
CheckBLank("txtnewpassword2"," Confirm New Password") && CheckAlphaNum("txtnewpassword2","Confirm New Password")&&
CompareAnyString("txtnewpassword1","txtnewpassword2",'passwords')
){
if ((document.getElementById('txtnewpassword1').value).length>=8){
return true;
}else {
alert ('Password need minimum 8 characters');
}
}
else
return false;
}
function ValidateForgetPwdData(){
username=document.getElementById('txtRegNumber').value;
if( CheckBLank("txtRegNumber","Register No/Student id") && CheckAlphaNum("txtRegNumber","Register No/Student id") &&
CheckBLank("txtMailid","Email")&& CheckEmail("txtMailid","Email")){
return true;
}
else
return false;
}
function funLoad(){
funLoadObject()
LoadLoginPage();
}
</script
After passing the Field Data from the Username and Password from the APP,
I need to getResources from the next Page of the Website accessing the Elements of the Tables generated!
[SEE ATTACHMENT 2]
and Post in different UI Pattern on my APP.
Additional Details:
I also need a basic understanding of how to manage and store cookies.
The website takes StudentID(as in the code) for Username and (Password) for password field.
What have try before?
Just start with HttpClient and analysis the given Login-Form. Does it use post or get, for example. Then rebuild it in your app.
Regards

Categories

Resources