GOOD_OR_BAD Detail_Add( const char *arg ) { char * arg_copy = owstrdup( arg ) ; char * next_p = arg_copy ; while ( next_p != NULL ) { BYTE sn[SERIAL_NUMBER_SIZE] ; BYTE length[SERIAL_NUMBER_SIZE] ; char * this_p = strsep( &next_p, " ," ) ; length[0] = SerialNumber_length( this_p, sn ) ; if ( length[0] > 0 ) { ++ DD.details ; switch (Globals.daemon_status) { case e_daemon_want_bg: case e_daemon_unknown: Globals.daemon_status = e_daemon_fg ; break ; default: break ; } DirblobAdd( sn, &(DD.sn) ) ; DirblobAdd( length, &(DD.length) ) ; } } return gbGOOD ; }
/* Used only in root_dir */ static void DS9490_dir_callback( void * v, const struct parsedname * pn_entry ) { struct dirblob * db = v ; LEVEL_DEBUG("Callback on %s",SAFESTRING(pn_entry->path)); if ( pn_entry->sn[0] != '\0' ) { DirblobAdd( pn_entry->sn, db ) ; } }
// Work around for omap hdq driver bug which reverses the slave address // We check the CRC8 and use reversed if forward is incorrect. static void search_callback( struct netlink_parse * nlp, void * v, const struct parsedname * pn ) { int i ; struct connection_in * in = pn->selected_connection ; struct device_search *ds = v ; BYTE sn[SERIAL_NUMBER_SIZE] ; BYTE * sn_pointer ; for ( i = 0 ; i < nlp->w1c->len ; i += SERIAL_NUMBER_SIZE ) { switch( in->master.w1.w1_slave_order ) { case w1_slave_order_forward: sn_pointer = &nlp->data[i] ; break ; case w1_slave_order_reversed: // reverse bytes sn[0] = nlp->data[i+7] ; sn[1] = nlp->data[i+6] ; sn[2] = nlp->data[i+5] ; sn[3] = nlp->data[i+4] ; sn[4] = nlp->data[i+3] ; sn[5] = nlp->data[i+2] ; sn[6] = nlp->data[i+1] ; sn[7] = nlp->data[i+0] ; sn_pointer = sn ; break ; case w1_slave_order_unknown: default: sn_pointer = &nlp->data[i] ; if ( CRC8(sn_pointer, SERIAL_NUMBER_SIZE) == 0 ) { in->master.w1.w1_slave_order = w1_slave_order_forward ; break ; } // reverse bytes sn[0] = nlp->data[i+7] ; sn[1] = nlp->data[i+6] ; sn[2] = nlp->data[i+5] ; sn[3] = nlp->data[i+4] ; sn[4] = nlp->data[i+3] ; sn[5] = nlp->data[i+2] ; sn[6] = nlp->data[i+1] ; sn[7] = nlp->data[i+0] ; sn_pointer = sn ; in->master.w1.w1_slave_order = w1_slave_order_reversed ; LEVEL_DEBUG( "w1 bus master%d uses reversed slave order", in->master.w1.id ) ; break ; } DirblobAdd(sn_pointer, &(ds->gulp) ); } }
static void GetDeviceName(const ASCII ** strpointer, struct connection_in * in) { BYTE sn[SERIAL_NUMBER_SIZE] ; BYTE dn[SERIAL_NUMBER_SIZE] ; if ( isxdigit((*strpointer)[0]) && isxdigit((*strpointer)[1]) ) { // family code specified sn[0] = string2num(*strpointer); *strpointer += 2; GetDefaultDeviceName( dn, sn, in ) ; // Choice of default or specified ID GetNextByte(strpointer,dn[1],&sn[1]); GetNextByte(strpointer,dn[2],&sn[2]); GetNextByte(strpointer,dn[3],&sn[3]); GetNextByte(strpointer,dn[4],&sn[4]); GetNextByte(strpointer,dn[5],&sn[5]); GetNextByte(strpointer,dn[6],&sn[6]); } else { const ASCII * name_to_familycode = namefind((*strpointer)) ; if ( name_to_familycode != NULL) { // device name specified (e.g. DS2401) sn[0] = string2num(name_to_familycode); GetDefaultDeviceName( dn, sn, in ) ; sn[1] = dn[1] ; sn[2] = dn[2] ; sn[3] = dn[3] ; sn[4] = dn[4] ; sn[5] = dn[5] ; sn[6] = dn[6] ; } else { // Bad device name LEVEL_DEFAULT("Device %d <%s> not recognized for %s %d -- ignored",DirblobElements(&(in->master.fake.main))+1,*strpointer,in->adapter_name,in->master.fake.index); return ; } } sn[SERIAL_NUMBER_SIZE-1] = CRC8compute(sn, SERIAL_NUMBER_SIZE-1, 0); DirblobAdd(sn, &(in->master.fake.main)); // Ignore bad return }
static GOOD_OR_BAD LINK_directory(struct device_search *ds, struct connection_in * in) { char resp[DEVICE_LENGTH+COMMA_LENGTH+PLUS_LENGTH+in->CRLF_size]; DirblobClear( &(ds->gulp) ); // Send the configuration command and check response RETURN_BAD_IF_BAD( LINK_search_type( ds, in )) ; // send the first search RETURN_BAD_IF_BAD(LINK_write(LINK_string("f"), 1, in)) ; //One needs to check the first character returned. //If nothing is found, the link will timeout rather then have a quick //return. This happens when looking at the alarm directory and //there are no alarms pending //So we grab the first character and check it. If not an E leave it //in the resp buffer and get the rest of the response from the LINK //device RETURN_BAD_IF_BAD(LINK_read(LINK_string(resp), 1, in)) ; switch (resp[0]) { case 'E': LEVEL_DEBUG("LINK returned E: No devices in alarm"); // pass through case 'N': // remove extra 2 bytes LEVEL_DEBUG("LINK returned E or N: Empty bus"); if (ds->search != _1W_CONDITIONAL_SEARCH_ROM) { in->AnyDevices = anydevices_no; } return gbGOOD ; default: break ; } if ( BAD(LINK_read(LINK_string(&resp[1+in->CRLF_size]), DEVICE_LENGTH+COMMA_LENGTH+PLUS_LENGTH-1-in->CRLF_size, in)) ) { return gbBAD; } // Check if we should start scanning switch (resp[0]) { case '-': case '+': if (ds->search != _1W_CONDITIONAL_SEARCH_ROM) { in->AnyDevices = anydevices_yes; } break; default: LEVEL_DEBUG("LINK_search unrecognized case"); return gbBAD; } /* Join the loop after the first query -- subsequent handled differently */ while ((resp[0] == '+') || (resp[0] == '-')) { BYTE sn[SERIAL_NUMBER_SIZE]; sn[7] = string2num(&resp[2]); sn[6] = string2num(&resp[4]); sn[5] = string2num(&resp[6]); sn[4] = string2num(&resp[8]); sn[3] = string2num(&resp[10]); sn[2] = string2num(&resp[12]); sn[1] = string2num(&resp[14]); sn[0] = string2num(&resp[16]); LEVEL_DEBUG("SN found: " SNformat, SNvar(sn)); // CRC check if (CRC8(sn, SERIAL_NUMBER_SIZE) || (sn[0] == 0x00)) { LEVEL_DEBUG("BAD family or CRC8"); return gbBAD; } DirblobAdd(sn, &(ds->gulp) ); switch (resp[0]) { case '+': // get next element if ( BAD(LINK_write(LINK_string("n"), 1, in))) { return gbBAD; } if ( BAD(LINK_read(LINK_string((resp)), DEVICE_LENGTH+COMMA_LENGTH+PLUS_LENGTH, in)) ) { return gbBAD; } break; case '-': return gbGOOD; default: break; } } return gbGOOD; }
// Read up to 7 (DS2490_DIR_GULP_ELEMENTS) at a time, and place into // a dirblob. Called from DS9490_next_both every 7 devices to fill. static enum search_status DS9490_directory(struct device_search *ds, const struct parsedname *pn) { BYTE status_buffer[ DS9490_getstatus_BUFFER_LENGTH + 1 ]; BYTE EP2_data[SERIAL_NUMBER_SIZE] ; //USB endpoint 3 buffer union { BYTE b[DS2490_BULK_BUFFER_SIZE] ; BYTE sn[DS2490_BULK_BUFFER_SIZE/SERIAL_NUMBER_SIZE][SERIAL_NUMBER_SIZE]; } EP3 ; //USB endpoint 3 buffer SIZE_OR_ERROR ret; int bytes_back; int devices_found; int device_index; int dir_gulp_elements = (pn->ds2409_depth==0) ? DS2490_DIR_GULP_ELEMENTS : 1 ; int readlen = 0 ; DirblobClear(&(ds->gulp)); if ( BAD( BUS_select(pn) ) ) { LEVEL_DEBUG("Selection problem before a directory listing") ; return search_error ; } if ( pn->selected_connection->AnyDevices == anydevices_no ) { // empty bus detected, no presence pulse detected return search_done ; } SetupDiscrepancy(ds, EP2_data); // set the search start location ret = DS9490_write(EP2_data, SERIAL_NUMBER_SIZE, pn) ; if ( ret < SERIAL_NUMBER_SIZE ) { LEVEL_DATA("bulk write problem = %d", ret); return search_error; } // Send the search request if ( BAD( USB_Control_Msg(COMM_CMD, COMM_SEARCH_ACCESS | COMM_IM | COMM_SM | COMM_F | COMM_RTS, (dir_gulp_elements << 8) | (ds->search), pn) ) ) { LEVEL_DATA("control error"); return search_error; } // read the search status if ( DS9490_getstatus(status_buffer, &readlen, pn) != BUS_RESET_OK ) { return search_error; } // test the buffer size waiting for us bytes_back = status_buffer[13]; LEVEL_DEBUG("Got %d bytes from USB search", bytes_back); if (bytes_back == 0) { /* Nothing found on the bus. Have to return something != search_good to avoid * getting stuck in loop in FS_realdir() and FS_alarmdir() * which ends when ret!=search_good */ LEVEL_DATA("ReadBufferstatus == 0"); return search_done; } else if ( bytes_back % SERIAL_NUMBER_SIZE != 0 ) { LEVEL_DATA("ReadBufferstatus size %d not a multiple of %d", bytes_back,SERIAL_NUMBER_SIZE); return search_error; } else if ( bytes_back > (dir_gulp_elements + 1) * SERIAL_NUMBER_SIZE ) { LEVEL_DATA("ReadBufferstatus size %d too large", bytes_back); return search_error; } devices_found = bytes_back / SERIAL_NUMBER_SIZE; if (devices_found > dir_gulp_elements) { devices_found = dir_gulp_elements; } // read in the buffer that holds the devices found if ((ret = DS9490_read(EP3.b, bytes_back, pn)) <= 0) { LEVEL_DATA("bulk read problem ret=%d", ret); return search_error; } // analyze each device found for (device_index = 0; device_index < devices_found; ++device_index) { /* test for CRC error */ LEVEL_DEBUG("gulp. Adding element %d:" SNformat, device_index, SNvar(EP3.sn[device_index])); if (CRC8(EP3.sn[device_index], SERIAL_NUMBER_SIZE) != 0 || EP3.sn[device_index][0] == 0) { LEVEL_DATA("CRC error"); return search_error; } } // all ok, so add the devices for (device_index = 0; device_index < devices_found; ++device_index) { DirblobAdd(EP3.sn[device_index], &(ds->gulp)); } ds->LastDiscrepancy = FindDiscrepancy(EP3.sn[devices_found-1], EP3.sn[devices_found]); ds->LastDevice = (bytes_back == devices_found * SERIAL_NUMBER_SIZE); // no more to read return search_good; }