int GSMInterface::initialise(SerialInterface *_serialInterface, String apn, String user,String Password, byte _gsmResetPin)
{
	serialinterface = _serialInterface;
	gsmResetPin = _gsmResetPin;
	resetGSM(_gsmResetPin);
    delay(2000);
	if(!registerGPRS_GSM())
    {
		return 504;
    }
    else
    {
    serialinterface->printlnToDebug("[GPRS CONNECTED]");
    }
    
	if(!attachGPRSContinue(apn,user,Password))
    {
        return 503;
    }
	else
    {
        serialinterface->printlnToDebug("[GPRS BEARER SELECTED]");
		return 200;
    }
}
//Response management.
void GSM3ShieldV1DataNetworkProvider::manageResponse(byte from, byte to)
{
	switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
	{
		case ATTACHGPRS:
			attachGPRSContinue();
			break;	
		case DETACHGPRS:
			detachGPRSContinue();
			break;
		case GETIP:
			getIPContinue();
			break;		
	}
}
//Attach GPRS main function.	
GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::attachGPRS(char* apn, char* user_name, char* password, bool synchronous)
{					
	user = user_name;
	passwd = password;
	// A sad use of byte reuse
	theGSM3ShieldV1ModemCore.setPhoneNumber(apn);

	theGSM3ShieldV1ModemCore.openCommand(this,ATTACHGPRS);
	theGSM3ShieldV1ModemCore.setStatus(CONNECTING);

	attachGPRSContinue();

	// If synchronous, wait till attach is over, or not.
	if(synchronous)
	{
		// if we shorten this delay, the command fails
		while(ready()==0) 
			delay(100); 
	}

	return theGSM3ShieldV1ModemCore.getStatus();	
}