142 |
static gn_error NK6510_GetFileList(gn_data *data, struct gn_statemachine *state); |
static gn_error NK6510_GetFileList(gn_data *data, struct gn_statemachine *state); |
143 |
static gn_error NK6510_GetFileId(gn_data *data, struct gn_statemachine *state); |
static gn_error NK6510_GetFileId(gn_data *data, struct gn_statemachine *state); |
144 |
static gn_error NK6510_GetFile(gn_data *data, struct gn_statemachine *state); |
static gn_error NK6510_GetFile(gn_data *data, struct gn_statemachine *state); |
145 |
|
static gn_error NK6510_GetFileById(gn_data *data, struct gn_statemachine *state); |
146 |
static gn_error NK6510_PutFile(gn_data *data, struct gn_statemachine *state); |
static gn_error NK6510_PutFile(gn_data *data, struct gn_statemachine *state); |
147 |
static gn_error NK6510_DeleteFile(gn_data *data, struct gn_statemachine *state); |
static gn_error NK6510_DeleteFile(gn_data *data, struct gn_statemachine *state); |
148 |
|
static gn_error NK6510_DeleteFileById(gn_data *data, struct gn_statemachine *state); |
149 |
|
static gn_error NK6510_GetFileDetailsById(gn_data *data, struct gn_statemachine *state); |
150 |
|
|
151 |
#ifdef SECURITY |
#ifdef SECURITY |
152 |
static gn_error NK6510_GetSecurityCodeStatus(gn_data *data, struct gn_statemachine *state); |
static gn_error NK6510_GetSecurityCodeStatus(gn_data *data, struct gn_statemachine *state); |
409 |
return NK6510_GetFileId(data, state); |
return NK6510_GetFileId(data, state); |
410 |
case GN_OP_GetFile: |
case GN_OP_GetFile: |
411 |
return NK6510_GetFile(data, state); |
return NK6510_GetFile(data, state); |
412 |
|
case GN_OP_GetFileById: |
413 |
|
return NK6510_GetFileById(data, state); |
414 |
case GN_OP_PutFile: |
case GN_OP_PutFile: |
415 |
return NK6510_PutFile(data, state); |
return NK6510_PutFile(data, state); |
416 |
case GN_OP_DeleteFile: |
case GN_OP_DeleteFile: |
417 |
return NK6510_DeleteFile(data, state); |
return NK6510_DeleteFile(data, state); |
418 |
|
case GN_OP_DeleteFileById: |
419 |
|
return NK6510_DeleteFileById(data, state); |
420 |
|
case GN_OP_GetFileDetailsById: |
421 |
|
return NK6510_GetFileDetailsById(data, state); |
422 |
default: |
default: |
423 |
return GN_ERR_NOTIMPLEMENTED; |
return GN_ERR_NOTIMPLEMENTED; |
424 |
} |
} |
1579 |
return sm_block(NK6510_MSG_FILE, data, state); |
return sm_block(NK6510_MSG_FILE, data, state); |
1580 |
} |
} |
1581 |
|
|
1582 |
|
static gn_error NK6510_GetFileDetailsById(gn_data *data, struct gn_statemachine *state) |
1583 |
|
{ |
1584 |
|
unsigned char req[] = {FBUS_FRAME_HEADER, 0x14, 0x00, 0x00, |
1585 |
|
0x00, 0x01, |
1586 |
|
0x00, 0x00 }; /* Location */ |
1587 |
|
int length, i; |
1588 |
|
|
1589 |
|
if (!data->file) |
1590 |
|
return GN_ERR_INTERNALERROR; |
1591 |
|
|
1592 |
|
length = data->file->id[0]; |
1593 |
|
for (i = 0; i < length; i++) { |
1594 |
|
req[8 + i] = data->file->id[i+1]; |
1595 |
|
} |
1596 |
|
length /= 2; |
1597 |
|
req[6] = (length & 0xff00) >> 8; |
1598 |
|
req[7] = (length & 0x00ff); |
1599 |
|
dprintf("Sending: %d %d %d %d\n", req[6], req[7], req[8], req[9]); |
1600 |
|
if (sm_message_send(8 + 2 * length, NK6510_MSG_FILE, req, state)) return GN_ERR_NOTREADY; |
1601 |
|
return sm_block(NK6510_MSG_FILE, data, state); |
1602 |
|
} |
1603 |
|
|
1604 |
static gn_error NK6510_GetFileId(gn_data *data, struct gn_statemachine *state) |
static gn_error NK6510_GetFileId(gn_data *data, struct gn_statemachine *state) |
1605 |
{ |
{ |
1606 |
unsigned char req[512] = {FBUS_FRAME_HEADER, 0x82, 0x00}; |
unsigned char req[512] = {FBUS_FRAME_HEADER, 0x82, 0x00}; |
1611 |
i = strlen(data->file->name); |
i = strlen(data->file->name); |
1612 |
req[5] = char_unicode_encode(req+6, data->file->name, i); |
req[5] = char_unicode_encode(req+6, data->file->name, i); |
1613 |
|
|
1614 |
if ( sm_message_send(req[5]+9, NK6510_MSG_FILE, req, state) ) return GN_ERR_NOTREADY; |
if (sm_message_send(req[5]+9, NK6510_MSG_FILE, req, state)) return GN_ERR_NOTREADY; |
1615 |
return sm_block(NK6510_MSG_FILE, data, state); |
return sm_block(NK6510_MSG_FILE, data, state); |
1616 |
} |
} |
1617 |
|
|
1626 |
unsigned char req4[] = {FBUS_FRAME_HEADER, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}; |
unsigned char req4[] = {FBUS_FRAME_HEADER, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}; |
1627 |
gn_error err; |
gn_error err; |
1628 |
int i; |
int i; |
1629 |
|
|
1630 |
if (!data->file) |
if (!data->file) |
1631 |
return GN_ERR_INTERNALERROR; |
return GN_ERR_INTERNALERROR; |
1632 |
i = strlen(data->file->name); |
i = strlen(data->file->name); |
1683 |
return sm_block(NK6510_MSG_FILE, data, state); |
return sm_block(NK6510_MSG_FILE, data, state); |
1684 |
} |
} |
1685 |
|
|
1686 |
|
static gn_error NK6510_GetFileById(gn_data *data, struct gn_statemachine *state) |
1687 |
|
{ |
1688 |
|
unsigned char req[] = {FBUS_FRAME_HEADER, 0x0e, 0x00, 0x00, |
1689 |
|
0x00, 0x01, |
1690 |
|
0x00, 0x00, /* Location */ |
1691 |
|
0x00, 0x00, 0x00, 0x00, /* Start position */ |
1692 |
|
0x00, 0x00, 0x00, 0x00}; /* Size */ |
1693 |
|
gn_error err; |
1694 |
|
int i, length; |
1695 |
|
|
1696 |
|
if (!data->file) |
1697 |
|
return GN_ERR_INTERNALERROR; |
1698 |
|
|
1699 |
|
length = data->file->id[0]; |
1700 |
|
for (i = 0; i < length; i++) { |
1701 |
|
req[8 + i] = data->file->id[i+1]; |
1702 |
|
} |
1703 |
|
length /= 2; |
1704 |
|
req[6] = (length & 0xff00) >> 8; |
1705 |
|
req[7] = (length & 0x00ff); |
1706 |
|
/* Get the data */ |
1707 |
|
while (data->file->togo > 0) { |
1708 |
|
int progress, offset; |
1709 |
|
|
1710 |
|
offset = 9 + 2 * length; |
1711 |
|
i = data->file->file_length - data->file->togo; |
1712 |
|
req[offset] = (i & 0xff0000) >> 16; |
1713 |
|
req[offset + 1] = (i & 0xff00) >> 8; |
1714 |
|
req[offset + 2] = i & 0xff; |
1715 |
|
if (data->file->togo > 0x100) { |
1716 |
|
req[offset + 5] = 0x01; |
1717 |
|
} else { |
1718 |
|
req[offset + 4] = (data->file->togo & 0xff0000) >> 16; |
1719 |
|
req[offset + 5] = (data->file->togo & 0xff00) >> 8; |
1720 |
|
req[offset + 6] = data->file->togo & 0xff; |
1721 |
|
} |
1722 |
|
if (sm_message_send(sizeof(req), NK6510_MSG_FILE, req, state)) |
1723 |
|
return GN_ERR_NOTREADY; |
1724 |
|
err = sm_block(NK6510_MSG_FILE, data, state); |
1725 |
|
if (err != GN_ERR_NONE) |
1726 |
|
return err; |
1727 |
|
progress = 100 * (data->file->file_length - data->file->togo) / data->file->file_length; |
1728 |
|
fprintf(stderr, _("Progress: %d%% completed\n"), progress); |
1729 |
|
} |
1730 |
|
|
1731 |
|
return err; |
1732 |
|
} |
1733 |
|
|
1734 |
static gn_error NK6510_PutFile(gn_data *data, struct gn_statemachine *state) |
static gn_error NK6510_PutFile(gn_data *data, struct gn_statemachine *state) |
1735 |
{ |
{ |
1736 |
unsigned char req1[512] = {FBUS_FRAME_HEADER, 0x72, 0x11, 0x00, 0x00}; |
unsigned char req1[512] = {FBUS_FRAME_HEADER, 0x72, 0x11, 0x00, 0x00}; |
1740 |
gn_error err; |
gn_error err; |
1741 |
int i; |
int i; |
1742 |
|
|
1743 |
if (!data->file) return GN_ERR_INTERNALERROR; |
if (!data->file) |
1744 |
|
return GN_ERR_INTERNALERROR; |
1745 |
i = strlen(data->file->name); |
i = strlen(data->file->name); |
1746 |
|
|
1747 |
/* Start the transfer */ |
/* Start the transfer */ |
1748 |
req1[7] = char_unicode_encode(req1+8, data->file->name, i); |
req1[7] = char_unicode_encode(req1+8, data->file->name, i); |
1749 |
data->file->togo = 0; |
data->file->togo = 0; |
1750 |
if (sm_message_send(req1[7]+12, NK6510_MSG_FILE, req1, state)) return GN_ERR_NOTREADY; |
if (sm_message_send(req1[7]+12, NK6510_MSG_FILE, req1, state)) |
1751 |
|
return GN_ERR_NOTREADY; |
1752 |
err = sm_block(NK6510_MSG_FILE, data, state); |
err = sm_block(NK6510_MSG_FILE, data, state); |
1753 |
if (err!=GN_ERR_NONE) return err; |
if (err != GN_ERR_NONE) |
1754 |
if (data->file->togo!=data->file->file_length) return GN_ERR_INTERNALERROR; |
return err; |
1755 |
|
if (data->file->togo != data->file->file_length) |
1756 |
|
return GN_ERR_INTERNALERROR; |
1757 |
|
|
1758 |
/* Put the data */ |
/* Put the data */ |
1759 |
while (data->file->togo>0) { |
while (data->file->togo > 0) { |
1760 |
i = data->file->togo; |
i = data->file->togo; |
1761 |
if (data->file->togo>0x100) { |
if (data->file->togo > 0x100) { |
1762 |
req2[12] = 0x01; |
req2[12] = 0x01; |
1763 |
data->file->just_sent = 0x100; |
data->file->just_sent = 0x100; |
1764 |
} else { |
} else { |
1765 |
req2[11] = (data->file->togo&0xff0000)>>16; |
req2[11] = (data->file->togo & 0xff0000) >> 16; |
1766 |
req2[12] = (data->file->togo&0xff00)>>8; |
req2[12] = (data->file->togo & 0xff00) >> 8; |
1767 |
req2[13] = data->file->togo&0xff; |
req2[13] = (data->file->togo & 0xff); |
1768 |
data->file->just_sent = data->file->togo; |
data->file->just_sent = data->file->togo; |
1769 |
} |
} |
1770 |
memcpy(req2+14, data->file->file + data->file->file_length - data->file->togo, data->file->just_sent); |
memcpy(req2+14, data->file->file + data->file->file_length - data->file->togo, data->file->just_sent); |
1771 |
if (sm_message_send(14+data->file->just_sent, NK6510_MSG_FILE, req2, state)) return GN_ERR_NOTREADY; |
if (sm_message_send(14+data->file->just_sent, NK6510_MSG_FILE, req2, state)) |
1772 |
|
return GN_ERR_NOTREADY; |
1773 |
err = sm_block(NK6510_MSG_FILE, data, state); |
err = sm_block(NK6510_MSG_FILE, data, state); |
1774 |
if (err!=GN_ERR_NONE) return err; |
if (err != GN_ERR_NONE) |
1775 |
if (data->file->togo!=i-data->file->just_sent) return GN_ERR_INTERNALERROR; |
return err; |
1776 |
|
if (data->file->togo!=i-data->file->just_sent) |
1777 |
|
return GN_ERR_INTERNALERROR; |
1778 |
} |
} |
1779 |
|
|
1780 |
/* Finish the transfer */ |
/* Finish the transfer */ |
1781 |
if (sm_message_send(sizeof(req3), NK6510_MSG_FILE, req3, state)) return GN_ERR_NOTREADY; |
if (sm_message_send(sizeof(req3), NK6510_MSG_FILE, req3, state)) return GN_ERR_NOTREADY; |
1782 |
return sm_block(NK6510_MSG_FILE, data, state); |
return sm_block(NK6510_MSG_FILE, data, state); |
1787 |
unsigned char req[512] = {FBUS_FRAME_HEADER, 0x62, 0x00}; |
unsigned char req[512] = {FBUS_FRAME_HEADER, 0x62, 0x00}; |
1788 |
int i; |
int i; |
1789 |
|
|
1790 |
if (!data->file) return GN_ERR_INTERNALERROR; |
if (!data->file) |
1791 |
|
return GN_ERR_INTERNALERROR; |
1792 |
i = strlen(data->file->name); |
i = strlen(data->file->name); |
1793 |
|
|
1794 |
req[5] = char_unicode_encode(req+6, data->file->name, i); |
req[5] = char_unicode_encode(req+6, data->file->name, i); |
1796 |
return sm_block(NK6510_MSG_FILE, data, state); |
return sm_block(NK6510_MSG_FILE, data, state); |
1797 |
} |
} |
1798 |
|
|
1799 |
|
static gn_error NK6510_DeleteFileById(gn_data *data, struct gn_statemachine *state) |
1800 |
|
{ |
1801 |
|
unsigned char req[10] = {FBUS_FRAME_HEADER, 0x1E, 0x00, 0x00, |
1802 |
|
0x00, 0x01, |
1803 |
|
0x00, 0x00}; /* file identifier */ |
1804 |
|
int i, length; |
1805 |
|
|
1806 |
|
if (!data->file) |
1807 |
|
return GN_ERR_INTERNALERROR; |
1808 |
|
|
1809 |
|
length = data->file->id[0]; |
1810 |
|
for (i = 0; i < length; i++) { |
1811 |
|
req[8 + i] = data->file->id[i+1]; |
1812 |
|
} |
1813 |
|
length /= 2; |
1814 |
|
req[6] = (length & 0xff00) >> 8; |
1815 |
|
req[7] = (length & 0x00ff); |
1816 |
|
if (sm_message_send(8 + length / 2, NK6510_MSG_FILE, req, state)) return GN_ERR_NOTREADY; |
1817 |
|
return sm_block(NK6510_MSG_FILE, data, state); |
1818 |
|
} |
1819 |
|
|
1820 |
|
|
1821 |
static gn_error NK6510_IncomingFile(int messagetype, unsigned char *message, int length, gn_data *data, struct gn_statemachine *state) |
static gn_error NK6510_IncomingFile(int messagetype, unsigned char *message, int length, gn_data *data, struct gn_statemachine *state) |
1822 |
{ |
{ |
1823 |
int i; |
int i, j, frame_length; |
1824 |
gn_file *file; |
gn_file *file; |
1825 |
|
gn_file_list *fll; |
1826 |
gn_error error = GN_ERR_NONE; |
gn_error error = GN_ERR_NONE; |
1827 |
|
|
1828 |
switch (message[3]) { |
switch (message[3]) { |
1829 |
|
case 0x0f: |
1830 |
|
/* Recv a block of file */ |
1831 |
|
if (data->file) { |
1832 |
|
i = (message[8] << 8) + message[9]; |
1833 |
|
memcpy(data->file->file + data->file->file_length - data->file->togo, message+10, i); |
1834 |
|
data->file->togo -= i; |
1835 |
|
} |
1836 |
|
break; |
1837 |
|
case 0x15: /* Answer for GetFileDetailsById */ |
1838 |
|
if (!data->file || !data->file_list) { |
1839 |
|
error = GN_ERR_INTERNALERROR; |
1840 |
|
dprintf("error!\n"); |
1841 |
|
goto out; |
1842 |
|
} |
1843 |
|
switch (message[4]) { |
1844 |
|
case 0x04: |
1845 |
|
error = GN_ERR_EMPTYLOCATION; |
1846 |
|
goto out; |
1847 |
|
case 0x01: /* OK */ |
1848 |
|
break; |
1849 |
|
default: |
1850 |
|
error = GN_ERR_UNKNOWN; |
1851 |
|
dprintf("error!\n"); |
1852 |
|
goto out; |
1853 |
|
} |
1854 |
|
if (!data->file) { |
1855 |
|
error = GN_ERR_INTERNALERROR; |
1856 |
|
dprintf("error!\n"); |
1857 |
|
goto out; |
1858 |
|
} |
1859 |
|
/* frame length */ |
1860 |
|
frame_length = 256 * message[8] + message[9]; |
1861 |
|
file = data->file; |
1862 |
|
fll = data->file_list; |
1863 |
|
char_unicode_decode(file->name, message + 10, 184); |
1864 |
|
dprintf("Filename: %s\n", file->name); |
1865 |
|
if (message[196] != 0xff) { |
1866 |
|
/* read timestamp */ |
1867 |
|
file->year = (message[210]<<8) + message[211]; |
1868 |
|
file->month = message[212]; |
1869 |
|
file->day = message[213]; |
1870 |
|
file->hour = message[214]; |
1871 |
|
file->minute = message[215]; |
1872 |
|
file->second = message[216]; |
1873 |
|
dprintf("Timestamp: %04d-%02d-%02d %02d:%02d:%02d\n", |
1874 |
|
file->year, file->month, file->day, |
1875 |
|
file->hour, file->minute, file->second); |
1876 |
|
} |
1877 |
|
file->togo = file->file_length = 256 * message[220] + message[221]; |
1878 |
|
dprintf("Filesize: %d bytes\n", file->file_length); |
1879 |
|
|
1880 |
|
switch (message[227]) { |
1881 |
|
case 0x00: |
1882 |
|
dprintf("directory\n"); |
1883 |
|
break; |
1884 |
|
case 0x01: |
1885 |
|
dprintf("java jed file\n"); |
1886 |
|
break; |
1887 |
|
case 0x02: |
1888 |
|
dprintf("image\n"); |
1889 |
|
break; |
1890 |
|
case 0x04: |
1891 |
|
dprintf("ringtone\n"); |
1892 |
|
break; |
1893 |
|
case 0x10: |
1894 |
|
dprintf("java jar file\n"); |
1895 |
|
break; |
1896 |
|
case 0x20: |
1897 |
|
dprintf("java rms file\n"); |
1898 |
|
break; |
1899 |
|
default: |
1900 |
|
dprintf("unknown file\n"); |
1901 |
|
} |
1902 |
|
|
1903 |
|
data->file_list->file_count = 0; |
1904 |
|
j = 0; |
1905 |
|
if (length > 0xe8) { |
1906 |
|
for (i = 250; i < length ;) { |
1907 |
|
int k, len = 2 * (message[i] * 256 + message[i+1]); |
1908 |
|
data->file_list->file_count++; |
1909 |
|
data->file_list->files[j] = calloc(1, sizeof(gn_file)); |
1910 |
|
data->file_list->files[j]->id = calloc(len + 1, sizeof(char)); |
1911 |
|
data->file_list->files[j]->id[0] = len; |
1912 |
|
for (k = 0; k < len; k++) { |
1913 |
|
data->file_list->files[j]->id[k+1] = message[i + 2 + k]; |
1914 |
|
} |
1915 |
|
i += (len + 2); |
1916 |
|
j++; |
1917 |
|
} |
1918 |
|
} |
1919 |
|
dprintf("%d subentries\n", data->file_list->file_count); |
1920 |
|
break; |
1921 |
|
case 0x1f: |
1922 |
|
/* file deleted */ |
1923 |
|
break; |
1924 |
case 0x59: |
case 0x59: |
1925 |
/* Sent a block of file ok */ |
/* Sent a block of file ok */ |
1926 |
if (data->file) { |
if (data->file) { |
1996 |
break; |
break; |
1997 |
case 0x83: |
case 0x83: |
1998 |
if (data->file) { |
if (data->file) { |
1999 |
memcpy(data->file->id, message+4, 6); |
int i; |
2000 |
|
|
2001 |
|
data->file->id = calloc(7, sizeof(char)); |
2002 |
|
for (i = 0; i < 6; i++) { |
2003 |
|
data->file->id[i] = message[4 + i]; |
2004 |
|
} |
2005 |
} |
} |
2006 |
break; |
break; |
2007 |
default: |
default: |