コード例 #1
0
int send_modem(const char * cmd)
{
    int err = 0;
    
    size_t cur = 0;
    ssize_t written;
    size_t len = strlen(cmd);
    
    if(open_modem() == -1) return -1; //AT_ERROR_GENERIC;

    LOGD("%s: AT> %s", logtime(), cmd);

    /* the main string */
    while (cur < len) {
        do {
            written = write (fd_smd, cmd + cur, len - cur);
        } while (written < 0 && errno == EINTR);

        if (written < 0) return -1;// AT_ERROR_GENERIC;

        cur += written;
    }
    /* the \r  */

    do {
        written = write (fd_smd, "\r" , 1);
    } while ((written < 0 && errno == EINTR) || (written == 0));

    if (written < 0) {
        LOGE("%s: send_modem: write failure", logtime());
        return -1; //AT_ERROR_GENERIC;
    }

    return written;
}
コード例 #2
0
struct RequestInfo requestCompleted(RIL_Token t)
{
    struct RequestInfo r = { .token=NULL, .request=0, .startTime=0};
    for(size_t i=0; i<sizeof(pendingRequests)/sizeof(struct RequestInfo) && pendingRequests[i].token!=NULL; i++) {
        if(pendingRequests[i].token==t) {
            r=pendingRequests[i];
            LOGD("%s: Request Complete %p %s after %d ms", logtime(), r.token, requestToString(r.request), (unsigned int)(clock()-r.startTime)/(CLOCKS_PER_SEC/1000));
            requestRemoveAt(i);
            return r;
        }
    }
    LOGD("%s: Request Complete %p not found in started list", logtime(),t);
    return r;
}

unsigned requestsPending()
{
    unsigned count=0;
    for(size_t i=0; i<sizeof(pendingRequests)/sizeof(struct RequestInfo) && pendingRequests[i].token!=NULL; i++) {
        if(pendingRequests[i].token!=NULL) {
            if((clock()-pendingRequests[i].startTime)/CLOCKS_PER_SEC > 10)
            {
                LOGD("%s: Request delete %p %s after %d ms", logtime(), pendingRequests[i].token, requestToString(pendingRequests[i].request), (unsigned int)(clock()-pendingRequests[i].startTime)/(CLOCKS_PER_SEC/1000));
                requestRemoveAt(i);
                i--;
            } else {
                count++;
            }
        }
    }
    return count;
}
コード例 #3
0
void requestsWaitComplete(char *msg){
    if(requestsPending()>0) {
        LOGD("%s: Request pending... waiting to complete", logtime());
        requestsLOGD();
        while(requestsPending()>0) msleep(1);
        LOGD("%s: Request completed... continue %s", logtime(), msg!=NULL ? msg : NULL);
    }
}
コード例 #4
0
void requestStarted(RIL_Token t, int request)
{
    LOGD("%s: Request Received %p %s", logtime(), t, requestToString(request)); 
    for(size_t i=0; i<sizeof(pendingRequests)/sizeof(struct RequestInfo); i++) {
        if(pendingRequests[i].token==NULL) {
            pendingRequests[i].token=t;
            pendingRequests[i].request=request;
            pendingRequests[i].startTime=clock();
            return;
        }
    }
    LOGD("%s: Request list full", logtime()); 
}
コード例 #5
0
bool
ImageBufAlgo::sub(ImageBuf& dst, Image_or_Const A_, Image_or_Const B_, ROI roi,
                  int nthreads)
{
    pvt::LoggedTimer logtime("IBA::sub");
    if (A_.is_img() && B_.is_img()) {
        const ImageBuf &A(A_.img()), &B(B_.img());
        if (!IBAprep(roi, &dst, &A, &B))
            return false;
        ROI origroi = roi;
        roi.chend = std::min(roi.chend, std::min(A.nchannels(), B.nchannels()));
        bool ok;
        OIIO_DISPATCH_COMMON_TYPES3(ok, "sub", sub_impl, dst.spec().format,
                                    A.spec().format, B.spec().format, dst, A, B,
                                    roi, nthreads);
        if (roi.chend < origroi.chend && A.nchannels() != B.nchannels()) {
            // Edge case: A and B differed in nchannels, we allocated dst to be
            // the bigger of them, but adjusted roi to be the lesser. Now handle
            // the channels that got left out because they were not common to
            // all the inputs.
            ASSERT(roi.chend <= dst.nchannels());
            roi.chbegin = roi.chend;
            roi.chend   = origroi.chend;
            if (A.nchannels() > B.nchannels()) {  // A exists
                copy(dst, A, dst.spec().format, roi, nthreads);
            } else {  // B exists
                copy(dst, B, dst.spec().format, roi, nthreads);
            }
        }
        return ok;
    }
    if (A_.is_val() && B_.is_img())  // canonicalize to A_img, B_val
        A_.swap(B_);
    if (A_.is_img() && B_.is_val()) {
        const ImageBuf& A(A_.img());
        cspan<float> b = B_.val();
        if (!IBAprep(roi, &dst, &A,
                     IBAprep_CLAMP_MUTUAL_NCHANNELS | IBAprep_SUPPORT_DEEP))
            return false;
        IBA_FIX_PERCHAN_LEN_DEF(b, A.nchannels());
        // Negate b (into a copy)
        int nc      = A.nchannels();
        float* vals = ALLOCA(float, nc);
        for (int c = 0; c < nc; ++c)
            vals[c] = -b[c];
        b = cspan<float>(vals, nc);
        if (dst.deep()) {
            // While still serial, set up all the sample counts
            dst.deepdata()->set_all_samples(A.deepdata()->all_samples());
            return add_impl_deep(dst, A, b, roi, nthreads);
        }
        bool ok;
        OIIO_DISPATCH_COMMON_TYPES2(ok, "sub", add_impl, dst.spec().format,
                                    A.spec().format, dst, A, b, roi, nthreads);
        return ok;
    }
    // Remaining cases: error
    dst.error("ImageBufAlgo::sub(): at least one argument must be an image");
    return false;
}
コード例 #6
0
bool
ImageBufAlgo::flip(ImageBuf &dst, const ImageBuf &src, ROI roi, int nthreads)
{
    if (&dst == &src) {    // Handle in-place operation
        ImageBuf tmp;
        tmp.swap (const_cast<ImageBuf&>(src));
        return flip (dst, tmp, roi, nthreads);
    }
    pvt::LoggedTimer logtime("IBA::flip");

    ROI src_roi = roi.defined() ? roi : src.roi();
    ROI src_roi_full = src.roi_full();
    int offset = src_roi.ybegin - src_roi_full.ybegin;
    int start = src_roi_full.yend - offset - src_roi.height();
    ROI dst_roi (src_roi.xbegin, src_roi.xend,
                 start, start+src_roi.height(),
                 src_roi.zbegin, src_roi.zend,
                 src_roi.chbegin, src_roi.chend);
    ASSERT (dst_roi.width() == src_roi.width() &&
            dst_roi.height() == src_roi.height());

    // Compute the destination ROI, it's the source ROI reflected across
    // the midline of the display window.
    if (! IBAprep (dst_roi, &dst, &src))
        return false;
    bool ok;
    OIIO_DISPATCH_COMMON_TYPES2 (ok, "flip", flip_,
                          dst.spec().format, src.spec().format,
                          dst, src, dst_roi, nthreads);
    return ok;
}
コード例 #7
0
bool
ImageBufAlgo::transpose (ImageBuf &dst, const ImageBuf &src,
                         ROI roi, int nthreads)
{
    pvt::LoggedTimer logtime("IBA::transpose");
    if (! roi.defined())
        roi = get_roi (src.spec());
    roi.chend = std::min (roi.chend, src.nchannels());
    ROI dst_roi (roi.ybegin, roi.yend, roi.xbegin, roi.xend,
                 roi.zbegin, roi.zend, roi.chbegin, roi.chend);
    bool dst_initialized = dst.initialized();
    if (! IBAprep (dst_roi, &dst))
        return false;
    if (! dst_initialized) {
        ROI r = src.roi_full();
        ROI dst_roi_full (r.ybegin, r.yend, r.xbegin, r.xend,
                          r.zbegin, r.zend, r.chbegin, r.chend);
        dst.set_roi_full (dst_roi_full);
    }
    bool ok;
    if (dst.spec().format == src.spec().format) {
        OIIO_DISPATCH_TYPES (ok, "transpose", transpose_, dst.spec().format,
                             dst, src, roi, nthreads);
    } else {
        OIIO_DISPATCH_COMMON_TYPES2 (ok, "transpose", transpose_, dst.spec().format,
                              src.spec().format, dst, src, roi, nthreads);
    }
    return ok;
}
コード例 #8
0
ファイル: BMS.cpp プロジェクト: Lhfcws/internship
int main(int argc, char* argv[]) {
    logtime();
    printf("Welcome to Blender Mocker Shell!!\n");

    processArgv(argc, argv);
    get_a_query("./querylist");
    printf("Command loaded!!\n");

    ret_t ret;
    ret = bmsHandler.init();
    printf("Init finished!!\n");

    if (ret == r_succeed) {
        ret = bmsHandler.handleNewRequest(input_query);
        printf("New Request handled!!\n");
    }

    if (ret == r_succeed) {
        ret = bmsHandler.handlePhase1Return();
        printf("Phase 1 Request handled!!\n");
    }

    if (ret == r_succeed) {
        ret = bmsHandler.handlePhase2Return();
        printf("Phase 2 Request handled!!\n");
    }

    printf("Exiting Blender Mocker Shell..\n");
    exit(0);
    return 0;
}
コード例 #9
0
int read_modem(char* response, size_t responseLen)
{
    if(open_modem() == -1) return -1;
    
    char *pread=response;
    while( pread<response+responseLen){
        if(read(fd_smd, pread, 1)<=0) break;
        if((*pread=='\n' || *pread=='\r') && pread==response) continue;
        if(*pread=='\r') break;
        pread++;
    }
    *pread=0;
    
    if(pread!=response) LOGD("%s: MODEM> %s", logtime(), response);
    else LOGD("%s MODEM>", logtime());
    
    return pread-response;
}
コード例 #10
0
void hackDeactivateData(void *data, size_t datalen, RIL_Token t)
{
    LOGD("%s: DeactivateData Request", logtime());
    char* cid = ((char **)data)[0];
    if(atoi(cid)!=1) {
        LOGE("    wrong CID %s expected 1", cid);
        return;
    }
    pthread_t tid;
    pthread_create(&tid, NULL, DeactivateData, t);   
}
コード例 #11
0
ファイル: output_alsa.c プロジェクト: astephanh/squeezelite
static void *alsa_error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...) {
	va_list args;
	if ((loglevel >= lINFO && err == 0) || loglevel >= lDEBUG) {
		fprintf(stderr, "%s ALSA %s:%d ", logtime(), function, line);
		va_start(args, fmt);
		vfprintf(stderr, fmt, args);
		fprintf(stderr, "\n");
		fflush(stderr);
	}
	return NULL;
}
コード例 #12
0
void* DeactivateData(void* t)
{
    dataConnectionState = DATA_STATE_DISCONNECTING;
    LOGD("%s: DeactivateData", logtime());
    
    int pid=pppd_pid; //work with pppd_pid copy as thread will set it to 0 after kill
    if(pid!=0) {
        int status=0;
        LOGD("    waiting for pppd to end %d", pid);
        kill(pid, SIGTERM);
        waitpid(pid, &status, 0);
        LOGD("%s: DeactivateData: pppd ended", logtime());
    }
    
    //clear dns entries
    property_set("net.ppp0.dns1", "");
    property_set("net.ppp0.dns2", "");
    
    dataConnectionState = DATA_STATE_DISCONNECTED;
    RIL_onRequestComplete((RIL_Token) t, RIL_E_SUCCESS, NULL, 0);
    return NULL;
}
コード例 #13
0
void interceptOnRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen)
{      
    if(!rmnet_mode) {
        struct RequestInfo requestInfo= requestCompleted(t);
        if( requestInfo.request==RIL_REQUEST_REGISTRATION_STATE) {
            if(responselen>=14*sizeof(char *)) {
                char **strings = (char **)response; 
                int registration = atoi(strings[0]);    //1 - Registered, home network; 5 - Registered, roaming
                int radio = atoi(strings[3]);           //0 == unknown
                registrationState=((registration==1 || registration==5) && radio!=0); 
                LOGD("%s: Registration state %d %d = %d", logtime(), registration, radio, registrationState);
                if(!registrationState && pppd_pid!=0 && dataConnectionState==DATA_STATE_CONNECTED){
                    LOGE("%s: data disconnect due to network registration state", logtime());
                    lastDataError=PDP_FAIL_REGISTRATION_FAIL;
                    dataConnectionState=DATA_STATE_CONNECTION_KILL;
                    kill(pppd_pid, SIGTERM);
                }
            }
        }
        if( requestInfo.request==RIL_REQUEST_GPRS_REGISTRATION_STATE) {
            if(responselen>=4*sizeof(char *)) {
                char **strings = (char **)response; 
                int registration = atoi(strings[0]);    //1 - Registered, home network; 5 - Registered, roaming
                int radio = atoi(strings[3]);           //0 == unknown; 4 ("unknown") is treated as "out of service" in the Android telephony system
                gprsRegistrationState=((registration==1 || registration==5) && (radio!=0 && radio!=4)); 
                LOGD("%s: Registration state %d %d = %d", logtime(), registration, radio, gprsRegistrationState);
                if(!gprsRegistrationState && pppd_pid!=0 && dataConnectionState==DATA_STATE_CONNECTED){
                    LOGE("%s: data disconnect due to gprs registration state", logtime());
                    lastDataError=PDP_FAIL_GPRS_REGISTRATION_FAIL;
                    dataConnectionState=DATA_STATE_CONNECTION_KILL;
                    kill(pppd_pid, SIGTERM);
                }
            }
        }
    }
    s_rilenv->OnRequestComplete(t, e, response, responselen);
}
コード例 #14
0
bool
ImageBufAlgo::div(ImageBuf& dst, Image_or_Const A_, Image_or_Const B_, ROI roi,
                  int nthreads)
{
    pvt::LoggedTimer logtime("IBA::div");
    if (A_.is_img() && B_.is_img()) {
        const ImageBuf &A(A_.img()), &B(B_.img());
        if (!IBAprep(roi, &dst, &A, &B, IBAprep_CLAMP_MUTUAL_NCHANNELS))
            return false;
        bool ok;
        OIIO_DISPATCH_COMMON_TYPES3(ok, "div", div_impl, dst.spec().format,
                                    A.spec().format, B.spec().format, dst, A, B,
                                    roi, nthreads);
        return ok;
    }
    if (A_.is_val() && B_.is_img())  // canonicalize to A_img, B_val
        A_.swap(B_);
    if (A_.is_img() && B_.is_val()) {
        const ImageBuf& A(A_.img());
        cspan<float> b = B_.val();
        if (!IBAprep(roi, &dst, &A,
                     IBAprep_CLAMP_MUTUAL_NCHANNELS | IBAprep_SUPPORT_DEEP))
            return false;

        IBA_FIX_PERCHAN_LEN_DEF(b, dst.nchannels());
        int nc      = dst.nchannels();
        float* binv = OIIO_ALLOCA(float, nc);
        for (int c = 0; c < nc; ++c)
            binv[c] = (b[c] == 0.0f) ? 0.0f : 1.0f / b[c];
        b = cspan<float>(binv, nc);  // re-wrap

        if (dst.deep()) {
            // While still serial, set up all the sample counts
            dst.deepdata()->set_all_samples(A.deepdata()->all_samples());
            return mul_impl_deep(dst, A, b, roi, nthreads);
        }
        bool ok;
        OIIO_DISPATCH_COMMON_TYPES2(ok, "div", mul_impl, dst.spec().format,
                                    A.spec().format, dst, A, b, roi, nthreads);
        return ok;
    }
    // Remaining cases: error
    dst.error("ImageBufAlgo::div(): at least one argument must be an image");
    return false;
}
コード例 #15
0
int open_modem() 
{
    if(fd_smd!=-1) return fd_smd;
    
    fd_smd = open ("/dev/smd0", O_RDWR);
    if(fd_smd  == -1) {
        LOGE("%s: send_modem: Error opening smd0", logtime());
        return -1; //AT_ERROR_GENERIC;
    }
    
    struct termios  ios;
    tcgetattr( fd_smd, &ios );
    ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
    tcsetattr( fd_smd, TCSANOW, &ios );
    
    //fcntl(fd_smd, F_SETFL, O_NONBLOCK | fcntl(fd_smd, F_GETFL, 0));
    
    return fd_smd;
}
コード例 #16
0
bool
ImageBufAlgo::rotate270 (ImageBuf &dst, const ImageBuf &src,
                         ROI roi, int nthreads)
{
    if (&dst == &src) {    // Handle in-place operation
        ImageBuf tmp;
        tmp.swap (const_cast<ImageBuf&>(src));
        return rotate270 (dst, tmp, roi, nthreads);
    }

    pvt::LoggedTimer logtime("IBA::rotate270");
    ROI src_roi = roi.defined() ? roi : src.roi();
    ROI src_roi_full = src.roi_full();

    // Rotated full ROI swaps width and height, and keeps its origin
    // where the original origin was.
    ROI dst_roi_full (src_roi_full.xbegin, src_roi_full.xbegin+src_roi_full.height(),
                      src_roi_full.ybegin, src_roi_full.ybegin+src_roi_full.width(),
                      src_roi_full.zbegin, src_roi_full.zend,
                      src_roi_full.chbegin, src_roi_full.chend);

    ROI dst_roi (src_roi.ybegin, src_roi.yend,
                 src_roi_full.xend-src_roi.xend,
                 src_roi_full.xend-src_roi.xbegin,
                 src_roi.zbegin, src_roi.zend,
                 src_roi.chbegin, src_roi.chend);

    ASSERT (dst_roi.width() == src_roi.height() &&
            dst_roi.height() == src_roi.width());

    bool dst_initialized = dst.initialized();
    if (! IBAprep (dst_roi, &dst, &src))
        return false;
    if (! dst_initialized)
        dst.set_roi_full (dst_roi_full);

    bool ok;
    OIIO_DISPATCH_COMMON_TYPES2 (ok, "rotate270", rotate270_,
                          dst.spec().format, src.spec().format,
                          dst, src, dst_roi, nthreads);
    return ok;
}
コード例 #17
0
ファイル: send_packet.c プロジェクト: pandax381/NAT64
verdict sendpkt_send(struct packet *in, struct packet *out)
{
	int error;

#ifdef BENCHMARK
	logtime(out);
#endif

	if (!route(out)) {
		kfree_skb(out->skb);
		return VERDICT_ACCEPT;
	}

	out->skb->dev = skb_dst(out->skb)->dev;
	log_debug("Sending skb.");

	error = whine_if_too_big(in, out);
	if (error) {
		kfree_skb(out->skb);
		return VERDICT_DROP;
	}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
	out->skb->ignore_df = true; /* FFS, kernel. */
#else
	out->skb->local_df = true; /* FFS, kernel. */
#endif

	error = dst_output(out->skb); /* Implicit kfree_skb(out->skb) goes here. */
	if (error) {
		log_debug("dst_output() returned errcode %d.", error);
		return VERDICT_DROP;
	}

	return VERDICT_CONTINUE;
}
コード例 #18
0
ファイル: trimhistory.c プロジェクト: tjyang/abmon
void trim_logs(time_t cutoff)
{
	filelist_t *fwalk;
	DIR *ldir = NULL, *sdir = NULL;
	struct dirent *sent, *lent;
	time_t ltime;
	char fn1[PATH_MAX], fn2[PATH_MAX];
	int itemno = 0;

	/* We have a list of directories to trim, so process them */
	for (fwalk = flhead; (fwalk); fwalk = fwalk->next) {
		dbgprintf("Processing %s\n", fwalk->fname);
		itemno++; if (progressinfo && ((itemno % progressinfo) == 0)) showprogress(itemno); 

		switch (fwalk->ftype) {
		  case F_DROPIT:
			/* It's an orphan, and we want to delete it */
			dropdirectory(fwalk->fname, 0);
			break;

		  case F_PURGELOGS:
			sdir = opendir(fwalk->fname);
			if (sdir == NULL) {
				errprintf("Cannot process directory %s: %s\n", fwalk->fname, strerror(errno));
				break;
			}

			while ((sent = readdir(sdir)) != NULL) {
				int allgone = 1;
				if (*(sent->d_name) == '.') continue;

				sprintf(fn1, "%s/%s", fwalk->fname, sent->d_name);
				ldir = opendir(fn1);
				if (ldir == NULL) {
					errprintf("Cannot process directory %s: %s\n", fn1, strerror(errno));
					continue;
				}

				while ((lent = readdir(ldir)) != NULL) {
					if (*(lent->d_name) == '.') continue;

					ltime = logtime(lent->d_name);
					if ((ltime > 0) && (ltime < cutoff)) {
						sprintf(fn2, "%s/%s", fn1, lent->d_name);
						if (unlink(fn2) == -1) {
							errprintf("Failed to unlink %s: %s\n", fn2, strerror(errno));
						}
					}
					else allgone = 0;
				}

				closedir(ldir);

				/* Is it empty ? Then remove it */
				if (allgone) rmdir(fn1);
			}

			closedir(sdir);
			break;

		  default:
			break;
		}
	}
}
コード例 #19
0
void hackSetupData(char **data, size_t datalen, RIL_Token t)
{
    LOGD("%s: SetupData(%s) Request", logtime(),((const char **)data)[2]);
    
    lastDataError=PDP_FAIL_ERROR_UNSPECIFIED;
    
    if(*data[0]=='0') {
        LOGE("    Android want us to connect as CDMA while we are a GSM phone !");
        goto error;
    }
    
    if(!registrationState) {
        LOGE("    network registration state wrong");
        lastDataError=PDP_FAIL_REGISTRATION_FAIL;
        goto error;
    }
    if(!gprsRegistrationState) {
        LOGE("    gprs registration state wrong");
        lastDataError=PDP_FAIL_GPRS_REGISTRATION_FAIL;
        goto error;
    }
    
    
    dataConnectionState = DATA_STATE_CONNECTING;
    char *apn = ((char **)data)[2];
    char *user = ((char **)data)[3];
    char *pass = ((char **)data)[4];
    if(apn==NULL) apn="";
    if(user==NULL || strlen(user)<2) user = "******";
    if(pass==NULL || strlen(pass)<2) pass = "******";
    strcpy(current_apn, apn);
    strcpy(current_user, user);
    
    //save auth
    truncate("/etc/ppp/pap-secrets", 0);
    truncate("/etc/ppp/chap-secrets", 0);
    char buff[128];
    sprintf(buff, "%s * %s\n", user, pass);
    int fd;
    if((fd=creat("/etc/ppp/pap-secrets", S_IRUSR|S_IWUSR))==-1) {
        LOGE("Failed to create /etc/ppp/pap-secrets");
        lastDataError=PDP_FAIL_USER_AUTHENTICATION;
        goto error;
    }
    write(fd, buff, strlen(buff));
    close(fd);
    if((fd=creat("/etc/ppp/chap-secrets", S_IRUSR|S_IWUSR))==-1) {
        LOGE("Failed to create /etc/ppp/chap-secrets");
        lastDataError=PDP_FAIL_USER_AUTHENTICATION;
        goto error;
    }
    write(fd, buff, strlen(buff));
    close(fd);  

    pthread_t tid;
    pthread_create(&tid, NULL, SetupData, t);  
    return;
    
    error:
        dataConnectionState=DATA_STATE_DISCONNECTED;
        RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
コード例 #20
0
void* SetupData(void* t)
{    
    //this should never happen but let's check
    if(pppd_pid!=0 ) {
        LOGD("    waiting pppd to die");
        int status=0;
        kill(pppd_pid, SIGTERM);
        waitpid(pppd_pid, &status, 0);
    }
    
    //reset ppp.dns 
    property_set("net.ppp0.dns1", "0.0.0.0");
    property_set("net.ppp0.dns2", "0.0.0.0");
    strcpy(current_addr, "255.255.255.255");
    
    pthread_t thread;
    pthread_create(&thread, NULL, pppd_thread, NULL);
   
    //wait for pppd connect
    if(ifc_init()) {
        LOGE("%s: IFC failed to init", logtime());
        sleep(7);
    } else {
        clock_t start=clock();
        //loop till timeout or connected
        while(1) {
            //check if ppp0 interface is up, if true break loop, else record dnschange value
            unsigned addr, mask, flags;
            ifc_get_info("ppp0", &addr, &mask, &flags);
            if(flags & 1) 
            {
                struct in_addr in_addr = {.s_addr=addr};
                strcpy(current_addr, inet_ntoa(in_addr));
                LOGD("%s: IP: %s", logtime(),current_addr); 
                break;        
            }
            //if timeout goto error
            if ( (clock()-start)/CLOCKS_PER_SEC > 60 ){
                LOGE("%s: ppp0 connect timed out, giving up", logtime());
                ifc_close();
                goto error;
            }
            int status, pid=pppd_pid;
            if(pid==0 || waitpid(pid, &status, WNOHANG)>0){
                LOGE("%s: ppp0 connect timed out, giving up", logtime());
                ifc_close();
                goto error;
            }
            msleep(100);
        }
    }
    ifc_close();
     
    //if ip-up exists wait for dns change
    char dns1[PROPERTY_VALUE_MAX];
    char dns2[PROPERTY_VALUE_MAX];
    struct stat sts;
    if(stat("/etc/ppp/ip-up", &sts)==0 && (S_ISREG(sts.st_mode) || S_ISLNK(sts.st_mode))) {
        clock_t start=clock();
        while(1) {
            //check if dnschange changed
            property_get("net.ppp0.dns1", dns1, "0.0.0.0");
            property_get("net.ppp0.dns2", dns2, "0.0.0.0");
            if(strcmp(dns1, "0.0.0.0")!=0 && strcmp(dns2, "0.0.0.0")!=0) break;
            
            if((clock()-start)/CLOCKS_PER_SEC > 2) {
                LOGE("%s: timeout waiting for dns change", logtime());
                break;
            }
            msleep(100);
        } 
    }
    
    //check ppp.dns values and set defaults if suspect wrong
    property_get("net.ppp0.dns1", dns1, "");
    if(strlen(dns1)<7 || strcmp(dns1,"0.0.0.0")==0 || strcmp(dns1, "10.11.12.13")==0) {
        LOGD("%s: DNS1: %s wrong setting to 8.8.8.8", logtime(),dns1);
        property_set("net.ppp0.dns1", "8.8.8.8");
    } else {
        LOGD("%s: DNS1: %s", logtime(),dns1);
    }
    property_get("net.ppp0.dns2", dns2, "");
    if(strlen(dns2)<7 || strcmp(dns2, "0.0.0.0")==0 || strcmp(dns2, "10.11.12.14")==0) {
        LOGD("%s: DNS2: %s wrong setting to 8.8.4.4", logtime(),dns2);
        property_set("net.ppp0.dns2", "8.8.4.4");
    } else {
        LOGD("%s: DNS2: %s", logtime(),dns2);
    }
    
    char *response[3] = { "1", "ppp0", current_addr };
    dataConnectionState=DATA_STATE_CONNECTED;
    RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
    return NULL;
    
    error:
        dataConnectionState=DATA_STATE_DISCONNECTED;
        RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
        return NULL;
}
コード例 #21
0
ファイル: time.cpp プロジェクト: marccodes/lfl
string logtime(Time t) { char buf[128] = {0}; logtime(t, buf, sizeof(buf)); return buf; }
コード例 #22
0
ファイル: time.cpp プロジェクト: marccodes/lfl
int logtime(char *buf, int size) { return logtime(Now(), buf, size); }
コード例 #23
0
void* pppd_thread(void *param)
{
    LOGD("%s: pppd_thread enter", logtime());
    
    requestsWaitComplete("pppd_thread");
    
    pppd_pid = fork();
    if(pppd_pid == 0) {
        
        char buff[256];
        kill(getppid(), SIGSTOP); //stop stealing my mojo 
        
        int act=0;
        
        send_modem("AT+CGACT?");
        do {
            read_modem(buff, sizeof(buff));
            char* actpos=strstr(buff, "+CGACT: 1,");
            if(actpos!=NULL) act=atoi(actpos+10);
        }while(buff[0]!='0');
        
        if(act!=0) {
            kill(getppid(), SIGCONT);
            exit(202);
        }

        sprintf(buff, "AT+CGDCONT=1,\"IP\",\"%s\",,0,0", current_apn);
        send_modem(buff);
        read_modem(buff, sizeof(buff));
        
        send_modem("ATD*99***1#");
        //send_modem("AT+CGDATA=\"PPP\",1");
        while(read_modem(buff, sizeof(buff))>0 && buff[0]=='+');
        //read_modem(buff, sizeof(buff));
        
        kill(getppid(), SIGCONT);

        int atd=atoi(buff);
        if(atd!=1 && atd!=3) exit(201); 

        sleep(1);

        close_modem(); //close modem handle before we transform to pppd
        int err = execl("/system/bin/pppd", "pppd", "/dev/smd1", "local","nodetach", "defaultroute", "noipdefault", "usepeerdns", "user", current_user, "debug", NULL);
        LOGE("%s: PPPD EXEC FAILED (%d)", logtime(),err);
        exit(200);
    } else {
        LOGD("%s: pppd pid is %d", logtime(),pppd_pid);
        
        int status=0;
        time_t start = time(NULL);
        waitpid(pppd_pid, &status, 0);
        pppd_pid=0;
        int runTime = time(NULL)-start;
        LOGD("%s: PPPD DIED after %d seconds with status %d", logtime(), runTime, status);
        
        if(lastDataError==PDP_FAIL_ERROR_UNSPECIFIED && WIFEXITED(status)){
            switch(WEXITSTATUS(status))
            {
                case 1: lastDataError=PDP_FAIL_INSUFFICIENT_RESOURCES; break;
                case 2: lastDataError=PDP_FAIL_SERVICE_OPTION_NOT_SUPPORTED; break;
                case 3: 
                case 4:
                    lastDataError=PDP_FAIL_PROTOCOL_ERRORS; break;
                case 19: lastDataError=PDP_FAIL_USER_AUTHENTICATION; break;
            }
        }
        
        requestsWaitComplete("pppd_thread");
        send_modem("AT+CGACT=0,1"); 
        
        if(dataConnectionState==DATA_STATE_CONNECTED || dataConnectionState==DATA_STATE_CONNECTION_KILL) {
            dataConnectionState=DATA_STATE_DISCONNECTED;
            RIL_Data_Call_Response dataCall={ .cid=1, .active=0, .type="IP", .apn=current_apn, .address=current_addr };
            s_rilenv->OnUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED, &dataCall, sizeof(RIL_Data_Call_Response));
        }
    }

    LOGD("%s: pppd_thread exit", logtime());
    return NULL;
}
コード例 #24
0
ファイル: time.cpp プロジェクト: marccodes/lfl
int logtime(Time t, char *buf, int size) { time_t tt=Time2time_t(t); return logtime(tt, (t-Seconds(tt)).count(), buf, size); }
コード例 #25
0
ファイル: time.cpp プロジェクト: marccodes/lfl
int logtime(time_t secs, int ms, char *buf, int size) { struct tm tm; localtm(secs, &tm); return logtime(&tm, ms, buf, size); }
コード例 #26
0
ファイル: socket.c プロジェクト: Shirling-VT/VTRST3.5
int processsocket(int sock,int inpipe) {

    fd_set fdset; /* selected file descriptors */
    int poll,i;

    struct timeval tv;

    sigset_t set;
    struct sigaction act;

    sigemptyset(&set);
    sigaddset(&set,SIGUSR1);

    act.sa_flags=0;
    act.sa_mask=set;
    act.sa_handler=trapreset;
    sigaction(SIGUSR1,&act,NULL);

    signal(SIGPIPE,SIG_IGN);

    listen(sock,5);

    tv.tv_sec=0;
    tv.tv_usec=0;

    poll=0;
    runloop=1;
    do {

        FD_ZERO(&fdset);
        FD_SET(inpipe,&fdset);
        if (poll==0) {
            if (pollsock(sock,NULL,&fdset) !=0) continue;
        } else pollsock(sock,&tv,&fdset);

        /* open any new connections if possible */

        opensock(sock,&fdset);

        poll=0;

        /* check to see if the root server has sent any data */

        if (FD_ISSET(inpipe,&fdset)) {
            int size;
            size=read(inpipe,mbuf,BUF_SIZE);
            if (size==0) break;

            /* log the time */

            logtime(timefname,size);
            writeraw(mbuf,size);
        }


        /* send the data to the clients */

        if (writesock() !=0) poll=1;

        /* read back any data from the clients */

        readsock(&fdset,tmpbuf,BUF_SIZE);

        /* decode the buffers here */

    } while(runloop);

    /* close all the clients down */

    for (i=0; i<msgmax; i++) {
        if (client[i].sock !=0) close(client[i].sock);
    }
    close(sock);
    return -1;
}
コード例 #27
0
ファイル: spy.c プロジェクト: MadCamel/energymech
void send_spy(const char *src, const char *format, ...)
{
	Chan	*chan;
	Mech	*backup;
	Spy	*spy;
	va_list	msg;
	const char *tempsrc;
	char	tempdata[MAXLEN];
	int	fd;
	int	printed = FALSE;

	tempsrc = (src == SPYSTR_STATUS) ? time2medium(now) : src;

#ifdef DEBUG
	debug("(send_spy) src %s format = '%s'\n",src,format);
#endif /* DEBUG */

	for(spy=current->spylist;spy;spy=spy->next)
	{
		if ((*src == '#' || *src == '*') && spy->t_src == SPY_CHANNEL)
		{
			if ((*src != '*') && stringcasecmp(spy->src,src))
				continue;
			if ((chan = find_channel_ac(spy->src)) == NULL)
				continue;
			if (find_chanuser(chan,CurrentNick) == NULL)
				continue;
			tempsrc = spy->src;
		}
		else
		/*
		 *  by using string constants we can compare addresses
		 */
		if (spy->src != src)
			continue;

		if (!printed)
		{
			printed = TRUE;
			va_start(msg,format);
			vsprintf(tempdata,format,msg);
			va_end(msg);
		}

		switch(spy->t_dest)
		{
		case SPY_DCC:
			to_file(spy->dcc->sock,"[%s] %s\n",tempsrc,tempdata);
			break;
		case SPY_CHANNEL:
			if (spy->destbot >= 0)
			{
				backup = current;
				for(current=botlist;current;current=current->next)
				{
					if (current->guid == spy->destbot)
					{
						to_server("PRIVMSG %s :[%s] %s\n",spy->dest,tempsrc,tempdata);
						break;
					}
				}
				current = backup;
			}
			else
			{
				to_user(spy->dest,"[%s] %s",tempsrc,tempdata);
			}
			break;
		case SPY_FILE:
			if ((fd = open(spy->dest,O_WRONLY|O_CREAT|O_APPEND,NEWFILEMODE)) >= 0)
			{
				to_file(fd,"[%s] %s\n",logtime(now),tempdata);
				close(fd);
			}
		}
	}
}
コード例 #28
0
                if(!gprsRegistrationState && pppd_pid!=0 && dataConnectionState==DATA_STATE_CONNECTED){
                    LOGE("%s: data disconnect due to gprs registration state", logtime());
                    lastDataError=PDP_FAIL_GPRS_REGISTRATION_FAIL;
                    dataConnectionState=DATA_STATE_CONNECTION_KILL;
                    kill(pppd_pid, SIGTERM);
                }
            }
        }
    }
    s_rilenv->OnRequestComplete(t, e, response, responselen);
}

void hackDataCallList(char **data, size_t datalen, RIL_Token t)
{
    RIL_Data_Call_Response dataCall={ .cid=1, .active=0, .type="IP", .apn=current_apn, .address=current_addr };
    LOGD("%s: DataCallList", logtime());
    LOGD("    cid=%d, active=%d, type=%s, apn=%s, add=%s", dataCall.cid, dataCall.active, dataCall.type, dataCall.apn, dataCall.address);
    s_rilenv->OnRequestComplete(t, RIL_E_SUCCESS, &dataCall, sizeof(RIL_Data_Call_Response));
}

void interceptOnUnsolicitedResponse(int unsolResponse, const void *data, size_t datalen)
{
    LOGD("%s: UNSOL %s", logtime(), requestToString(unsolResponse));
    s_rilenv->OnUnsolicitedResponse(unsolResponse, data, datalen);
}

void (*htc_onRequest)(int request, void *data, size_t datalen, RIL_Token t);
void onRequest(int request, void *data, size_t datalen, RIL_Token t) {
    if(!rmnet_mode) {
        switch(request) {
            case RIL_REQUEST_SETUP_DATA_CALL: