?? tlv.c
字號:
update current_tlv, current_tlv_tag, current_tlv_len and current_tlv_val with the found TLV ber. return jtrue if the tag has been found, jfalse otherwise. ========================================================================= */#ifdef JAYACFG_DO_NOT_SUPPORT_RETURNTYPE_JBOOLjbyte __tlv_seek_next_tag(jword tag)#elsejbool __tlv_seek_next_tag(jword tag)#endif{ BIOS_SETERR(NOERR); LOG1("TLV","__tlv_seek_next_tag(): tag = %.4X",tag); do { next_tlv = __tlv_get_tag(); if (lasterr!=NOERR) { LOG2("TLV","__tlv_seek_next_tag(): tag = %.4X - NOT FOUND because ERROR %d !",tag,lasterr); BIOS_SETERR(NOERR); return jfalse; } if (current_tlv_tag==tag) { LOG3("TLV","__tlv_seek_next_tag(): tag = %.4X - FOUND adr=%.4X len=%d",tag,current_tlv_val,current_tlv_len); return jtrue; } } while (next_tlv<(current_EF.u3.body_ef+current_EF.u4.sizefile)); LOG1("TLV","__tlv_seek_next_tag(): tag = %.4X - NOT FOUND !",tag); return jfalse;}/* ============================================================================ __tlv_internal_update_tag() update tag, len and value in place (size has been made for this new value) DANGER: internal use only to this module. return jtrue if the tag has been updated, jfalse otherwise. ========================================================================= */#ifdef JAYACFG_DO_NOT_SUPPORT_RETURNTYPE_JBOOLjbyte __tlv_internal_update_tag(jword tag,jword len,jbyte xdata * value)#elsejbool __tlv_internal_update_tag(jword tag,jword len,jbyte xdata * value)#endif{ LOCAL(jbyte,b); LOCAL(jword,i); LOG3("TLV","__tlv_internal_update_tag(): tag = %.4X len=%d value=%.4X",tag,len,value); /* store the tag */ b = (tag>>8); if (b==0) { if ((tag&0x001F)==(0x001F)) { BIOS_SETERR(ERR_INVALID_TAG); return jfalse; } } else { if ((b&0x1F)!=(0x1F)) { BIOS_SETERR(ERR_INVALID_TAG); return jfalse; } /* double byte tag */ HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)(tag>>8)); } HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)(tag&0x00FF)); /* store the len */ if (len<=127) { /* one byte */ HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)len); } else if (len<=255) { /* two bytes */ HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)0x81); HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)len); } else { /* three bytes */ HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)0x82); HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)(len>>8)); HAL_EEPROM_WRITE_BYTE(current_tlv++,(jbyte)(len&0xFF)); } /* store the value */ for (i=0; i<len;i++) { HAL_EEPROM_WRITE_BYTE(current_tlv++,value[i]); } return jtrue;}/* ============================================================================ __tlv_append_inplace_tag() tag seek already done (and failed) / append it inplace __tlv_append_tag() check if the tag exist / append it only if not found ------------------------------------------------------------------------- returns: jtrue if the TLV was added, jfalse otherwise. ========================================================================= */#ifdef JAYACFG_DO_NOT_SUPPORT_RETURNTYPE_JBOOLjbyte __tlv_append_inplace_tag(jword tag,jword len,jbyte xdata * value)#elsejbool __tlv_append_inplace_tag(jword tag,jword len,jbyte xdata * value)#endif{ LOG3("TLV","__tlv_append_inplace_tag(): tag = %.4X len=%d value=%.4X",tag,len,value); /* next_tlv is already adressing the first free cell ! */ /* enough place to store the tag ? __x replace 2 with the real value given the tag value */ if ((next_tlv+len+2+__tlv_size_of_length(len))>=(current_EF.u3.body_ef+current_EF.u4.sizefile)) { BIOS_SETERR(ERR_OUT_OF_MEMORY); return jfalse; } /* copy inplace ! */ current_tlv = next_tlv; return __tlv_internal_update_tag(tag,len,value);}#ifdef JAYACFG_DO_NOT_SUPPORT_RETURNTYPE_JBOOLjbyte __tlv_append_tag(jword tag,jword len,jbyte xdata * value)#elsejbool __tlv_append_tag(jword tag,jword len,jbyte xdata * value)#endif{ LOG3("TLV","__tlv_append_tag(): tag = %.4X len=%d value=%.4X",tag,len,value); if (__tlv_seek_first_tag(tag)) { BIOS_SETERR(ERR_TAG_ALREADY_EXIST); return jfalse; } return __tlv_append_inplace_tag(tag,len,value);}/* ============================================================================ __tlv_update_inplace_tag() tag seek already done (and success) / update it inplace __tlv_update_tag() check if the tag exist / update it only if found ------------------------------------------------------------------------- we have three cases : - same size - smaller size - bigger size returns: jtrue if the TLV ber was updated, jfalse otherwise. ========================================================================= */#ifdef JAYACFG_DO_NOT_SUPPORT_RETURNTYPE_JBOOLjbyte __tlv_update_inplace_tag(jword tag,jword len,jbyte xdata * value)#elsejbool __tlv_update_inplace_tag(jword tag,jword len,jbyte xdata * value)#endif{ LOCAL(jword,i); LOCAL(jint16,delta); LOG3("TLV","__tlv_update_inplace_tag(): tag = %.4X len=%d value=%.4X",tag,len,value); /* adjust delta on the number of bytes required for the length */ delta = len-current_tlv_len+__tlv_size_of_length(len)-__tlv_size_of_length(current_tlv_len); if (delta==0) { /* same size -> update in place ! */ if (!__tlv_internal_update_tag(tag,len,value)) { /* IMPOSSIBLE ! tag has been already accepted */ BIOS_SETERR(ERR_FAULT); return jfalse; } return jtrue; } if (delta>0) { /* BIGGER SIZE */ #if 1 BIOS_SETERR(ERR_FUNCTION_UNSUPPORTED); return jfalse; #else /* enough place to store the updated tag ? */ !? free_ber_area !? if ((free_ber_area+delta)>=(current_EF.u3.body_ef+current_EF.u4.sizefile)) { BIOS_SETERR(ERR_OUT_OF_MEMORY); return jfalse; } /* move the next tag to have the place ! begin from the end in case of failure during the move */ for (i=free_ber_area-1;i>=next_ber;i--) { HAL_EEPROM_WRITE_BYTE((jword)(i+delta),HAL_EEPROM_READ_BYTE(i)); } /* note: ber_seek_tag() has already positioned current_ber the tag we need to update ! */ if (!__tlv_internal_update_tag(tag,len,value)) { /* IMPOSSIBLE ! tag has been already accepted */ BIOS_SETERR(ERR_FAULT); return jfalse; } free_ber_area += delta; return jtrue; #endif } /* LESSER SIZE */ /* clear the bytes at the end (note:delta<0) */ for (i=next_tlv+delta-1;i<next_tlv;i++) { HAL_EEPROM_WRITE_BYTE(i,0xFF); } if (!__tlv_internal_update_tag(tag,len,value)) { /* IMPOSSIBLE ! tag has been already accepted */ BIOS_SETERR(ERR_FAULT); return jfalse; } return jtrue;}#ifdef JAYACFG_DO_NOT_SUPPORT_RETURNTYPE_JBOOLjbyte __tlv_update_tag(jword tag,jword len,jbyte xdata * value)#elsejbool __tlv_update_tag(jword tag,jword len,jbyte xdata * value)#endif{ LOG3("TLV","__tlv_update_tag(): tag = %.4X len=%d value=%.4X",tag,len,value); /* seek the tag, updating current_ber_len, current_ber_val, ... */ if (!__tlv_seek_first_tag(tag)) { BIOS_SETERR(ERR_TAG_NOT_FOUND); return jfalse; } return __tlv_update_inplace_tag(tag,len,value);}/* ========================================================================= That's all folks ! ========================================================================= */#endif/* JAYA_TLV */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -